c# – Windows Phone应用程序背景图像
发布时间:2020-12-16 00:03:18 所属栏目:百科 来源:网络整理
导读:我正在尝试更改app.xaml中所有xaml页面的背景图像,但未成功. 我在App构造函数中尝试以下操作: var imageBrush = new ImageBrush{ ImageSource = new BitmapImage(new Uri("/Images/SomeBackgroundImage.png",UriKind.Relative))};RootFrame.Background = im
我正在尝试更改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(); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |