c# - Xamarin Forms - 如何将背景图像添加到内容页面

标签 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>

bg1.jpg 是我的可移植项目中的图像,我想将其设置为背景并且我已设置属性

  • Build Action = "Content"
  • 复制到输出目录 = "Copy Always"

下面是我项目的目录结构。

Directory Structure

最佳答案

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

对于 Android Resources/drawable

iOS 资源

关于c# - Xamarin Forms - 如何将背景图像添加到内容页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38949707/

相关文章:

c# - 检查一个控件是否是 "touching"另一个控件

wpf - 如何清除 MVVM 中的文本框?

c# - 具有两个主键时的 FluentNhibernate 映射

c# - 具有来自后台线程的回调的 WCF 服务?

c# - 如何访问 ASP.NET Core 服务中的路由数据/值提供程序数据?

c# - 如何使用 Rx 遍历一系列带有停顿和淡入淡出的字符串?

wpf - 自定义 Mahapps.MetroWindow 关闭按钮

c# - 如何在 android Xamarin 中动态填充表格布局?

c# - Xamarin Monotouch UISplitViewController : How can I set or create the delegate for UISplitViewController?

mvvm - 为什么 Xamarin.Forms 中的 MvvmLight 优于 Mvvm?