【问题标题】:Platform specific CornerRadius on <Frame> Xamarin.Forms<Frame> Xamarin.Forms 上的平台特定 CornerRadius
【发布时间】:2018-10-19 11:17:13
【问题描述】:

我正在尝试在 iOSAndroid 上分配不同的 CornerRadius,如下所示:

<Frame
    HasShadow="false"
    Padding="10"
    BackgroundColor="Red">
    <Frame.CornerRadius>
        <OnPlatform x:TypeArguments="x:Double">
            <On
                Platform="iOS">20</On>
            <On
                Platform="Android">30</On>
        </OnPlatform>
    </Frame.CornerRadius>
    <Label
        Text="Hello World" />
</Frame>

但是得到一个

无法分配属性“CornerRadius”:属性不存在,或者不可分配,或者值和属性之间的类型不匹配

我试过x:TypeArguments="Thickness"x:TypeArguments="x:Int32"。反编译程序集发现CornerRadiusfloat 类型。但是x namespace 中没有Float 属性,我的意思是x:TypeArguments="x:Float" 不存在。

任何想法我做错了什么或者这是一个错误?

【问题讨论】:

    标签: xaml xamarin xamarin.forms


    【解决方案1】:

    CornerRadius 类型是 Single

    <Frame HasShadow="true" OutlineColor="Red">
        <Frame.CornerRadius>
            <OnPlatform x:TypeArguments="x:Single">
                <On Platform="iOS" Value="20"/>
                <On Platform="Android" Value="30"/>
            </OnPlatform>
        </Frame.CornerRadius>
        <Frame.Content>
            <Label Text="Welcome to Xamarin Forms!" VerticalOptions="Center" HorizontalOptions="Center" />
        </Frame.Content>
    </Frame>
    

    【讨论】:

    • @envyM6,没问题,很高兴它有帮助,?
    • 在 Xamarin.Forms 4.5+ 上,x:TypeArguments 属性应设置为“Int32”
    【解决方案2】:

    我觉得这里有一个语法错误,请执行以下操作:

    <Frame.CornerRadius>
     <OnPlatform x:TypeArguments="x:Single">
            <OnPlatform.Platforms>
                <On Platform="iOS" Value="20" />
                <On Platform="Android" Value="30" />
                <On Platform="UWP" Value="30" />
            </OnPlatform.Platforms>
        </OnPlatform>
     </Frame.CornerRadius>
    

    试试这个,如果它不起作用,请恢复。

    【讨论】:

    • 谢谢哥们,但事实并非如此,语法是正确的。但是,我也尝试了您的解决方案。错误是Type CornerRadius not found
    • 那是因为我假设你会将它添加到父框架中,而不是像那样没有任何东西
    • 对于其他人来说...... UWP = x:Int32,这里的挑战是支持2种类型......通过定义正确类型的值并在onplatform中引用它来做到这一点
    猜你喜欢
    • 2016-11-20
    • 2015-10-14
    • 1970-01-01
    • 2015-04-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多