c# - 当用户从 Windows Phone 的设置页面中选择它时切换 ResourceDictionary

标签 c# windows-phone-7 xaml

我在我的 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/

相关文章:

c# - 在使用 Mono/Unity3D 的 Android 设备上使用 RabbitMQ 的问题

c# - 如何调整图像 C#.net Windows 窗体

data-binding - 如何在 WP7 中将多个值数据绑定(bind)到单个 TextBlock.Text?

caching - Windows Phone 7 是否缓存 Web 请求?

c# - 在 MediaElement 中流式传输 Youtube 视频 - Windows 应用商店应用

c# - SignalR 安全 : how is it working?

c# - 调整浏览器窗口大小时如何停止页面刷新(跳转)?

c# - 将 json 转换为自定义对象数组

wpf - 在服务器端从 Silverlight 4 XAML 生成图像,而无需在浏览器中呈现 UI

c# - 从 xaml 中的按钮继承的自定义按钮在命名空间中不存在错误