Xamarin表单 - 如何将背景图像添加到内容页面

con*_*per 6 c# xaml xamarin xamarin.forms

我正在尝试将背景图像分配给我设计的内容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="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>
Run Code Online (Sandbox Code Playgroud)

bg1.jpg 我的便携式项目中的图像,我想设置为背景,我已设置属性

  • Build Action = "Content"
  • Copy to Output Directory = "Copy Always"

以下是我的项目的目录结构.

目录结构

Yeh*_*kyi 13

我的建议是将图像放到文件夹中:

对于Android Resources/drawable

对于iOS Resources