2013-12-18 37 views
7

我想实现某种工厂模式XAML的。我为WinRT创建了一个应用程序,我在其中定义了两个xaml样式文件。基本上,想什么,我实现(如果可能的话)是在应用程序启动时加载两个XAML文件之一。 在Solution Explorer中我有这样的:XAML的WinRT - 工厂模式自定义样式

enter image description here

CustomStyles foder包含样式文件。因此,基于枚举在我App.xaml.cs文件

public enum Style 
{ 
    Style_1, 
    Style_2 
} 

如果我选择Style_1我想加载XAML文件Style_1.xaml其他Style_2.xaml在运行。 无论是样式文件,有钮扣的款式,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> 

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> 

有一种方法可以达到我想要做什么?先谢谢你。

+1

好像你正在寻找[主题化(http://stackoverflow.com/questions/11150570/how-to-implement-theming-in-wpf)。不过,我不确定WinRT XAML对此有多大的支持。 –

+0

你还需要奖励吗? :) – pinckerman

+0

如果你想添加更多的声誉,随意:) – davideberdin

回答

2

我们最终做这样的事情:

  1. 定义ResourcesDictionary在App.xaml中所有的CustomStyles

  2. 我们作出这样的决定,其自定义样式具有对服务器的请求使用这一段代码Application.Current.Resources[CustomStyleVariable];加载

  3. 我们加载整个样式在Style对象。

我们还没有找到任何更好的解决方案,但它似乎工作。