Xamarin Forms - 如何将背景图像添加到内容页面 [英] Xamarin Forms - how to add background image to a content page
本文介绍了Xamarin Forms - 如何将背景图像添加到内容页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试为我在 xaml
中设计的内容分配背景图像.我尝试了不同的方法,但没有显示背景图像.这是我写的代码:
I am trying to assign Background Image to my content designed in xaml
. I have tried different approaches but it is not showing me background image. Here is the code I have written:
内容页面:
<?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="Demo.Welcome"
BackgroundImage="bg1.jpg">
<ContentPage.Content>
<StackLayout HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand" Spacing="25" Padding="0" x:Name="stackLayoutMain">
<Label FontSize="40" Text="WelCome Page" HorizontalOptions="Start" VerticalOptions="StartAndExpand"></Label>
<Entry Placeholder="Activation Key" WidthRequest="200" FontSize="15" HorizontalOptions="Center" VerticalOptions="StartAndExpand" TextChanged="entryActivationTextChanged" x:Name="entryActivationKey" Keyboard="Numeric" HorizontalTextAlignment="Center"></Entry>
<Button
x:Name="buttonActivate"
BackgroundColor="#fff"
Text="Activate"
WidthRequest="100"
HeightRequest="50"
HorizontalOptions="Center"
VerticalOptions="StartAndExpand"
TextColor="#377CC1"
IsVisible="False"
Clicked="buttonActivateClicked" >
</Button>
</StackLayout>
</ContentPage.Content>
</ContentPage>
bg1.jpg
是我的便携式项目中的图像,我想将其设置为背景并且我已经设置了属性
bg1.jpg
is image in my portable project which i want to set as a background and I have set property
Build Action = "Content"
和复制到输出目录=始终复制"
下面是我项目的目录结构.
And Below is the directory structure of my project.
推荐答案
我的建议是把图片放到文件夹中:
My suggestion is to put images to folder:
for Android Resources/drawable
iOS 资源
这篇关于Xamarin Forms - 如何将背景图像添加到内容页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文