小编Bej*_*asc的帖子

XAML资源字典中的算术运算

我想做的事

我最近一直在探索XAML资源词典.它们非常强大,但是为了减少(甚至进一步)为了适应任何修改而需要进行的更改,我想使用一些基本的算术运算来改变它的HeightRequest属性Entry.

我已经在充分利用OnPlatformOnIdiom不同方面,比如FontSize.

对于iOS平台,我想做HeightRequest一个条目20+(FontSize).将FontSize使用已经设置OnIdiom(它略有增加粒).

在一个完美的世界里,我正在努力做的核心事情可能看起来像
<Setter Property="HeightRequest" Value="{DynamicResource StandardFontSize}+10">

什么"有效"

我有一个工作的解决方案,如果我使用的组合OnIdiomOnPlatform.

<?xml version="1.0" encoding="utf-8" ?>
<Application xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="XamarinDesigner.App"
             xmlns:local="clr-namespace:XamarinDesigner"
             >
    <Application.Resources>
        <ResourceDictionary>
            <OnIdiom x:Key="StandardFontSize" x:TypeArguments="x:Double"  Tablet="22" Phone="18"/>
            <Style x:Key="MyEntry" TargetType="Entry">
                <Setter Property="FontSize" Value="{DynamicResource StandardFontSize}"/>
                <Setter Property="HeightRequest">
                    <Setter.Value>
                        <OnIdiom x:TypeArguments="x:Double">
                            <OnIdiom.Phone>
                                <OnPlatform x:TypeArguments="x:Double" iOS="30"/>
                            </OnIdiom.Phone>
                            <OnIdiom.Tablet>
                                <OnPlatform x:TypeArguments="x:Double" iOS="40"/>
                            </OnIdiom.Tablet>
                        </OnIdiom>
                    </Setter.Value>
                </Setter>
                <Setter Property="VerticalOptions" Value="Center"/> …
Run Code Online (Sandbox Code Playgroud)

xaml resourcedictionary ivalueconverter xamarin.forms

5
推荐指数
1
解决办法
432
查看次数