gpt4 book ai didi

c# - Windows Phone 应用程序背景图片

转载 作者:行者123 更新时间:2023-11-30 13:27:36 25 4
gpt4 key购买 nike

我正在尝试更改 app.xaml 中所有 xaml 页面的背景图片,但没有成功。

我正在 App 构造函数中尝试以下操作:

var imageBrush = new ImageBrush
{
ImageSource = new BitmapImage(new Uri("/Images/SomeBackgroundImage.png", UriKind.Relative))
};

RootFrame.Background = imageBrush;

我不想在页面级别执行此操作,因为所有页面都将具有相同的背景图片,具体取决于用户选择的主题。

关于我在这里做错了什么的想法?

最佳答案

我最终做了什么:

我创建了一个方法来根据所选主题选择正确的背景图像。

public static ImageBrush GetBackground()
{
var imageBrush = new ImageBrush();

if ((Visibility)App.Current.Resources["PhoneLightThemeVisibility"] == Visibility.Visible)
{
imageBrush = new ImageBrush
{
ImageSource = new BitmapImage(new Uri("/Images/Background1.png", UriKind.Relative))
};
}
else
{
imageBrush = new ImageBrush
{
ImageSource = new BitmapImage(new Uri("/Images/Background2.png", UriKind.Relative))
};
}

return imageBrush;
}

并且在每个页面中我都设置了背景图片。

LayoutRoot.Background = Utils.GetBackground();

关于c# - Windows Phone 应用程序背景图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10045848/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com