且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Xamarin.Forms 如何在应用程序的所有页面上添加背景图像

更新时间:2023-11-11 12:40:16

要在 App.xaml 中添加背景图片,您可以通过以下方式进行:

To add your background image in App.xaml, you can procede this way:

<?xml version="1.0" encoding="utf-8" ?>
<Application
    x:Class="YourProject.App"
    xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:yourProject="clr-namespace:YourProject;assembly=YourProject">
  <Application ...>
    <Application.Resources>
        <ResourceDictionary>
           <FileImageSource x:Key="MyBackgroundImage">bgImage.jpg</FileImageSource>
        </ResourceDictionary>
    </Application.Resources>
</Application>

然后在你看来,你引用它

And then in your view, you reference it

<Image Source="{ StaticResource MyBackgroundImage}" />