2016-11-10 67 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中即可。 –