spa*_*unk 7 c# xaml winrt-xaml
我想为XAML实现一种工厂模式.我为WinRT创建了一个应用程序,我在其中定义了两个xaml样式文件.基本上,我想要实现的(如果可能的话)是在应用程序启动时加载两个xaml文件中的一个.在解决方案资源管理器中我有这个:

CustomStyles foder包含样式文件.所以,基于我的App.xaml.cs文件中的枚举器
public enum Style
{
Style_1,
Style_2
}
Run Code Online (Sandbox Code Playgroud)
如果我选择Style_1,我想在运行时加载xaml文件Style_1.xaml else Style_2.xaml.两个样式文件都具有相同的Button样式,TextBlock样式等定义,具有不同的属性值.这是一个例子:
Style_1.xaml
<Style x:Key="Attribute_Label" TargetType="TextBlock">
<Setter Property="FontFamily" Value="Segoe UI" />
<Setter Property="Foreground" Value="#78CAB3" />
<Setter Property="FontSize" Value="15" />
<Setter Property="FontWeight" Value="Normal" />
</Style>
Run Code Online (Sandbox Code Playgroud)
Style_2.xaml
<Style x:Key="Attribute_Label" TargetType="TextBlock">
<Setter Property="FontFamily" Value="Arial" />
<Setter Property="Foreground" Value="#606060" />
<Setter Property="FontSize" Value="30" />
<Setter Property="FontWeight" Value="Normal" />
</Style>
Run Code Online (Sandbox Code Playgroud)
有办法实现我想做的事情吗?先感谢您.
我们最终会做这样的事情:
在 App.xaml 中使用所有 CustomStyles定义ResourcesDictionary
我们发出一个服务器请求来决定必须加载哪种自定义样式
使用这段代码,Application.Current.Resources[CustomStyleVariable];我们将整个样式加载到 Style 对象中。
我们还没有找到更好的解决方案,但它似乎有效。