2016-11-10 112 views
0

我试图设置ContentsPage BackgroundImage,但在大型屏蔽设备上图像保持平铺。Xamarin Forms ContentPage背景图片拼贴

有没有人知道如何停止平铺图像?

EDITED

这里是发生了什么在iPad上的图像。

enter image description here

这就是它看起来像在手机上:

enter image description here

MainPage.cs

namespace Application.Views 
{ 
    public partial class MainPage : ContentPage 
    { 
     RegisterDevice registerDevice; 
     MenuAnimations menuAnimations; 

     private double width; 

     public MainPage() 
     { 
      InitializeComponent(); 

      registerDevice = new RegisterDevice(); 
      menuAnimations = new MenuAnimations(); 

      ToolbarItems.Add(new ToolbarItem 
      { 
       Icon = "menuBtn.png", 
       Order = ToolbarItemOrder.Primary 
      }); 
     } 

     protected override void OnSizeAllocated(double width, double height) 
     { 
       BackgroundImage = "bg_portrait.png"; 
     } 
    } 
} 

MainPage.xaml中

<?xml version="1.0" encoding="utf-8" ?> 
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
      xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
      x:Class="Application.Views.MainPage"> 
    <ContentPage.Content> 
    </ContentPage.Content> 
</ContentPage> 
+0

请加上屏幕截图。 –

+0

我已经添加了iPad的屏幕截图。 – ADuggan

+0

请添加'XAML'代码。以及它应该如何看起来(从较小的设备屏幕)。谢谢。 –

回答

2

在这方面BackgroundImage属性是类型string我不能使用属性<Image>,Aspect例如。所以我最好在XAML

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
     xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
     x:Class="SuperForms.Samples.Page1"> 
    <ContentView> 
    <Image Source="https://i.stack.imgur.com/ajyCo.png" 
      Aspect="AspectFill"/> 
    </ContentView> 
</ContentPage> 
+0

这似乎工作,但我打算使用StackLayout来保存我的组件和whatnot。我如何覆盖图像上的堆栈布局?我需要使用AbsoluteLayout还是什么? – ADuggan

+0

只需使用'Grid'而不是'ContentView'并将'Stack'放入Grid中即可。 –