我在我的 Windows Phone 应用程序中创建了一些 ResourceDictionaries,并在 App.xaml.cs 文件中添加了这段代码以加载主题:
private void LoadDictionary()
{
var dictionaries = Resources.MergedDictionaries;
dictionaries.Clear();
string source = String.Format("/MyApp;component/Themes/Theme2.xaml");
var themeStyles = new ResourceDictionary { Source = new Uri(source, UriKind.Relative) };
dictionaries.Add(themeStyles);
}
当我更改代码并重新编译它时,这工作正常,但我想要但无法弄清楚的是;如何在用户从设置页面选择主题时加载字典?
我在 XAML 中为 TextBox 设置样式的方式是这样的:
<TextBox x:Name="Count" Grid.Column="1" TextAlignment="Center" InputScope="Number">
<TextBox.Style>
<StaticResource ResourceKey="InputTextBox" />
</TextBox.Style>
</TextBox>
最佳答案
您通常会使用 DynamicResource 执行此操作(请参阅本文 WPF Switch Color Theme ),但不幸的是,我们在 Windows Phone 中没有这种奢侈。
我唯一的建议是使用一个带有属性的全局类来处理你想要交换的东西,然后通过 SetTheme() 方法手动处理交换。
关于c# - 当用户从 Windows Phone 的设置页面中选择它时切换 ResourceDictionary,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10523922/