【问题标题】:Make some OnIdiom and OnPlatform StaticResource制作一些 OnIdiom 和 OnPlatform StaticResource
【发布时间】:2019-04-01 08:01:35
【问题描述】:

我想使用StaticResource 并从 VS 2017 的自动完成中受益,如果存在的话,可以使用类似这样的语法:

<x:Double x:Key="NormalSpacing">
    <OnIdiom x:TypeArguments="x:Double">
        <OnIdiom.Phone>
            <OnPlatform x:TypeArguments="x:Double" iOS="7" Android="3" />
        </OnIdiom.Phone>
        <OnIdiom.Tablet>
            <OnPlatform x:TypeArguments="x:Double" iOS="15" Android="10" />
        </OnIdiom.Tablet>
    </OnIdiom>
</x:Double>

很快我想给出包含OnIdiomOnPlatform标签的主标签的关键。

【问题讨论】:

    标签: c# xaml xamarin xamarin.forms


    【解决方案1】:

    使用紧凑的OnIdiomOnPlatformsyntax 自动完成样式:

    <Style x:Key="stackLayoutStyle" TargetType="StackLayout">
        <Setter Property="Spacing" 
                Value="{OnIdiom 
            Phone  = {OnPlatform iOS=7,  Android=3   },
            Tablet = {OnPlatform iOS=15, Android=10 }}" >
        </Setter>
    </Style>
    ...
    <StackLayout Style="{StaticResource stackLayoutStyle}">
    ...
    </StackLayout>
    

    【讨论】:

    • 我把style用在别的事情上,有没有别的办法?
    猜你喜欢
    • 2021-08-10
    • 1970-01-01
    • 2017-02-27
    • 2019-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-23
    相关资源
    最近更新 更多