【发布时间】:2017-07-24 14:34:44
【问题描述】:
[UWP]
我有许多来自 App.xaml 的颜色绑定网格
MainPage.xaml ...
<Grid
Height="45"
Margin="0,0,0,10"
Background="{ThemeResource MyColor}">
App.xaml
<Application
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
RequestedTheme="Dark">
<Application.Resources>
<ResourceDictionary>
<SolidColorBrush x:Key="MyColor">#FFFFFF</SolidColorBrush>
然后我想用这样的代码更改它的所有内容
Application.Current.Resources["MyColor"] = new SolidColorBrush(Windows.UI.Color.FromArgb(255, 242, 101, 34));
但它不起作用。我可以错过什么吗?当我导航到另一个页面并返回时,上面的代码会抛出 System.Exception
【问题讨论】:
-
什么意思,它不起作用?是否抛出异常,
Grids 的背景颜色是否无法改变? -
颜色不变。没有例外
-
当我导航到另一个页面并返回时,上面的代码会抛出 System.Exception