微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用 OnIdiom 和 AbsoluteLayout

如何解决使用 OnIdiom 和 AbsoluteLayout

我有圆形按钮,正在尝试使用 AbsolutLayout 更改它们的大小,具体取决于它们是在手机上还是平板电脑上。

这是我的 xaml:

<Frame BackgroundColor="{StaticResource ThemeColor}" Padding="0" CornerRadius="40" AbsoluteLayout.LayoutBounds="{StaticResource HomeCircle}" AbsoluteLayout.LayoutFlags="PositionProportional"> 
    <Label Text="&#xf5a0;" HorizontalOptions="Center" VerticalOptions="Center" Style="{StaticResource Icon}" TextColor="{StaticResource LabelColor}"/> 
    <Frame.GestureRecognizers> 
        <TapGestureRecognizer Tapped="Directions"/> 
    </Frame.GestureRecognizers> 
</Frame> 

<AbsoluteLayout.Resources> 
    <ResourceDictionary> 
        <OnIdiom x:Key="HomeCircle" x:TypeArguments="Frame" Phone=".85,.375,80,80"
                                                            Tablet=".85,120,120"/> 
    </ResourceDictionary> 
</AbsoluteLayout.Resources>

我查看了此资源,但它不起作用:

How to use attached properties such as Grid.Row,AbsoluteLayout.LayoutFlags to OnPlatform tag in Xamarin Forms

编辑:尝试了 Rectangle、AbsoluteLayout 和 Frame 的 TypeArguments,它们都给出了这个错误

错误 XFC0009 找不到“电话”的属性、BindableProperty 或事件,或者值和属性间的类型不匹配。

编辑:也看过这个帖子,它提供了同样的错误

https://xamarin.github.io/bugzilla-archives/55/55183/bug.html

解决方法

我过去也遇到过同样的问题。我的解决方案是通过 Binding 代替 StaticResource 来设置 AbsoluteLayout 边界。

在视图模型中:

foo({ first: "hi",second: "man" },"somethingElse")

在 yaml 中:

public Xamarin.Forms.Rectangle HomeCircle => Xamarin.Forms.Device.Idiom == TargetIdiom.Phone ? new Xamarin.Forms.Rectangle(0.5f,0.5f,80,80) : new Xamarin.Forms.Rectangle(0.5f,120,120);

反正 AbsoluteLayout.LayoutBounds 需要 Rectangle,而标记并不总是允许一切:)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。