如何根据XAML中的平台移动boxview的位置
这是我为boxview编写的代码XAML,它位于absolutelayout中如何根据XAML中的平台移动boxview的位置,xaml,xamarin,xamarin.forms,Xaml,Xamarin,Xamarin.forms,这是我为boxview编写的代码XAML,它位于absolutelayout中 <BoxView BackgroundColor="#04388C" AbsoluteLayout.LayoutBounds="0,1,1,.1" AbsoluteLayout.LayoutFlags="All"/> 上面显示的absolutelayout.layoutbounds是针对我的ANDROID设备的,但对于IOS,我需要它是“0,0,1,1”才能位于顶部 让我放一个截图↓↓↓↓↓ 单击
<BoxView BackgroundColor="#04388C" AbsoluteLayout.LayoutBounds="0,1,1,.1" AbsoluteLayout.LayoutFlags="All"/>
上面显示的absolutelayout.layoutbounds是针对我的ANDROID设备的,但对于IOS,我需要它是“0,0,1,1”才能位于顶部
让我放一个截图↓↓↓↓↓ 单击图像的链接
IOS屏幕底部的蓝色框我需要它在顶部
在XAML中:
<BoxView x:Name="MyBoxView"/>
注意:Device.OnPlatform(iOsValue、androidValue、WinValue)根据运行平台设置不同的值
更新:
上述代码将向我们发出以下警告信息:
[系统.过时(“OnPlatform从2.3.4版开始就过时了。请改用switch(RuntimePlatform)。”)]
为了解决此问题,我们可以使用以下代码:
AbsoluteLayout.SetLayoutFlags(MyBoxView, AbsoluteLayoutFlags.All);
switch (Device.RuntimePlatform)
{
case Device.Android:
{
AbsoluteLayout.SetLayoutBounds(MyBoxView, new Rectangle(0, 1, 1, 0.1));
break;
}
case Device.iOS:
{
AbsoluteLayout.SetLayoutBounds(MyBoxView, new Rectangle(0, 0, 1, 0.1));
break;
}
}
在XAML中:
<BoxView x:Name="MyBoxView"/>
注意:Device.OnPlatform(iOsValue、androidValue、WinValue)根据运行平台设置不同的值
更新:
上述代码将向我们发出以下警告信息:
[系统.过时(“OnPlatform从2.3.4版开始就过时了。请改用switch(RuntimePlatform)。”)]
为了解决此问题,我们可以使用以下代码:
AbsoluteLayout.SetLayoutFlags(MyBoxView, AbsoluteLayoutFlags.All);
switch (Device.RuntimePlatform)
{
case Device.Android:
{
AbsoluteLayout.SetLayoutBounds(MyBoxView, new Rectangle(0, 1, 1, 0.1));
break;
}
case Device.iOS:
{
AbsoluteLayout.SetLayoutBounds(MyBoxView, new Rectangle(0, 0, 1, 0.1));
break;
}
}
仅限XAML:
<ResourceDictionary>
<OnPlatform x:Key="layoutBounds" x:TypeArguments="Rectangle">
<On Platform="iOS">0,0,1,.1</On>
<On Platform="Android, UWP">0,1,1,.1</On>
</OnPlatform>
</ResourceDictionary>
...
<AbsoluteLayout>
<BoxView BackgroundColor="Blue"
AbsoluteLayout.LayoutBounds="{StaticResource layoutBounds}"
AbsoluteLayout.LayoutFlags="All"/>
</AbsoluteLayout>
0,0,1,.1
0,1,1,.1
...
仅限XAML:
<ResourceDictionary>
<OnPlatform x:Key="layoutBounds" x:TypeArguments="Rectangle">
<On Platform="iOS">0,0,1,.1</On>
<On Platform="Android, UWP">0,1,1,.1</On>
</OnPlatform>
</ResourceDictionary>
...
<AbsoluteLayout>
<BoxView BackgroundColor="Blue"
AbsoluteLayout.LayoutBounds="{StaticResource layoutBounds}"
AbsoluteLayout.LayoutFlags="All"/>
</AbsoluteLayout>
0,0,1,.1
0,1,1,.1
...
显示此消息Device.OnPlatform(T,T,T)”已过时:“使用交换机(RuntimePlatform)代替任何其他选项?显示此消息Device.OnPlatform(T,T,T)”已过时:“使用交换机(RuntimePlatform)代替任何其他选项?”?