我'm currently working on a PCL project in Xamarin forms and started working on the iOS implementation because I finished the Android one. The problem I' m有的是我的视图的背景图像被放大(就像工具栏上的图标一样) . 它's probably using the full sized image so I' d期望使用像 Aspect=Aspect.AspectFit
这样的东西但是因为我使用的是PCL代码我使用的是 Background= Height>Width ? <picture_string_portrait> : <picture_string_landscape>
,它需要一个字符串 . 我可以't seem to figure out how to fix this +I can only share default code since this is for a company I'目前正在工作(所以我也不担心屏幕) .
这是我的pcl代码(myview.xaml.cs)的一部分,它在加载和方向更改时命中 . 在Android中,它可以很好地扩展,但在iOS中却没有 .
private void OnSizeChanged(object sender, EventArgs eventArgs)
{
BackgroundImage = Height > Width ? "background_portrait.jpg" : "background_landscape.jpg";
}
如果这是一个菜鸟问题我道歉但我已经完成了我的谷歌分享,似乎无法找到任何有用的东西 . 对所有人都有效的PCL解决方案将不胜感激 .
提前致谢!
1 回答
ContentPage.BackgroundImage
的问题在于你可以't control it'的宽高比 . 看到设备如何具有各种尺寸和形状,替代解决方案可能会更好地为您服务 . 您可以通过在ContentPage
中使用Image
并使用Aspect
来实现相同的结果 . 一种方法是这样的AbsoluteLayout
:另一个是在这个示例中使用
RelativeLayout
:http://dotnetbyexample.blogspot.nl/2015/02/using-full-size-none-stretched.html