2013-12-18 33 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對象。

我們還沒有找到任何更好的解決方案,但它似乎工作。