Lit*_*nny 4 xaml orientation xamarin xamarin.forms
我知道如何显示内容页面,但如何根据方向选择正确的布局。我想编写 xaml 文件:一个用于垂直方向,另一个用于水平方向。方向改变时是否可以切换xaml文件
Xamarin.Forms 不提供任何本机事件来通知你的应用共享代码中的方向更改。但是,Page 的 SizeChanged 事件会在 Page 的宽度或高度发生更改时触发。当 Page 的宽度大于高度时,设备处于横向模式。
protected override void OnSizeAllocated (double width, double height){
base.OnSizeAllocated (width, height);
if (width != this.width || height != this.height) {
this.width = width;
this.height = height;
if (width > height) {
// landscape
} else {
// portrait
}
}
}
Run Code Online (Sandbox Code Playgroud)
有了这个,您可以根据方向以编程方式将页面内容更改为新内容。
Content = // new content here.
Run Code Online (Sandbox Code Playgroud)
对于某些患者,您可以尝试使用相同的 XAML,但仅更改某些视图的方向,例如此处。
来源在这里。
| 归档时间: |
|
| 查看次数: |
2142 次 |
| 最近记录: |