C# Windows10背后代码中的Xaml合并

C# Windows10背后代码中的Xaml合并,c#,xaml,windows-10,C#,Xaml,Windows 10,我想在运行期间在我的应用程序(UAP Windows10)中更改一些颜色。 我是这样做的 while (App.Current.Resources.MergedDictionaries.Count() > 2) { App.Current.Resources.MergedDictionaries.RemoveAt(App.Current.Resources.MergedDictionaries.Count() - 1); } if (index < 0 || index >

我想在运行期间在我的应用程序(UAP Windows10)中更改一些颜色。 我是这样做的

while (App.Current.Resources.MergedDictionaries.Count() > 2)
{
  App.Current.Resources.MergedDictionaries.RemoveAt(App.Current.Resources.MergedDictionaries.Count() - 1);
}

if (index < 0 || index > 2) { index = 0; }
ResourceDictionary dict = new ResourceDictionary();
dict.Source = new Uri(App.uri_colors[(int)index], UriKind.RelativeOrAbsolute);
Application.Current.Resources.MergedDictionaries.Add(dict);
while(App.Current.Resources.MergedDictionaries.Count()>2)
{
App.Current.Resources.MergedDictionaries.RemoveAt(App.Current.Resources.MergedDictionaries.Count()-1);
}
如果(索引<0 | |索引>2){index=0;}
ResourceDictionary dict=新建ResourceDictionary();
dict.Source=新Uri(App.Uri_colors[(int)index],UriKind.RelativeOrab溶质);
Application.Current.Resources.MergedDictionaries.Add(dict);
它在应用程序启动时第一次工作,但在运行时颜色不会改变。但是,当前值发生了变化


我需要刷新一下吗?非常感谢您的帮助

您是否使用DynamicSource引用了这些资源?我的资源存储在3个不同的文件中(RED.xaml、GREEN.xaml、BLUE.xaml)。我创建了一个包含3个不同字符串uri的静态列表。那不是你的问题吗?不,我的问题是,你如何使用这些资源。像Background=“{DynamicResource BackgroundBrush}”对不起。Background=“{StaticResource app_color}”将其更改为DynamicResource