在xamarin.forms中将背景图像设置为相对布局
如何将背景图像设置为xamarin.forms项目中的相对布局 我尝试了以下代码: Xamal文件:在xamarin.forms中将背景图像设置为相对布局,xamarin.forms,Xamarin.forms,如何将背景图像设置为xamarin.forms项目中的相对布局 我尝试了以下代码: Xamal文件: 您可以在相对布局中添加图像视图,请参见以下链接 如果要在XAML文件中为Xamarin项目中的整个页面添加背景图像,请使用BackgroundImage属性 <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2
您可以在相对布局中添加图像视图,请参见以下链接
如果要在XAML文件中为Xamarin项目中的整个页面添加背景图像,请使用BackgroundImage属性
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:PhoneDailerDemo"
x:Class="PhoneDailerDemo.MainPage"
BackgroundImage="image3.jpg">
<Label Text="Welcome to Xamarin Forms!"
VerticalOptions="Center"
HorizontalOptions="Center" />
<StackLayout Padding="100">
//..........
</StackLayout>
</ContentPage>
这对我来说是可行的,但图像会扭曲成比例。如何将图像设置为居中和填充?
public partial class MainApp : ContentPage
{
public Image BGImage { get; set; }
public MainApp()
{
this.BackgroundImage = "/Images/landing_page.jpg";
BindingContext = this;
InitializeComponent();
}
}
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:PhoneDailerDemo"
x:Class="PhoneDailerDemo.MainPage"
BackgroundImage="image3.jpg">
<Label Text="Welcome to Xamarin Forms!"
VerticalOptions="Center"
HorizontalOptions="Center" />
<StackLayout Padding="100">
//..........
</StackLayout>
</ContentPage>