Xamarin表单ContentPage背景图片平铺

时间:2016-11-10 09:53:44

标签: xamarin.forms

我试图设置ContentsPage BackgroundImage但是在大屏幕设备上图像保持平铺。

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

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>

1 个答案:

答案 0 :(得分: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>
相关问题