I'd like to implement a sort of Factory Pattern for XAML. I created an app for WinRT where I defined two xaml style files. Basically, what I'd like to achieve (if possible) is to load one of the the two xaml file when the application starts. in the solution explorer I have this:
CustomStyles foder contains the style files. So, based on an enumerator in my App.xaml.cs file
public enum Style
{
Style_1,
Style_2
}
if I choose Style_1 I'd like to load the xaml file Style_1.xaml else Style_2.xaml at run-time. Both the style files, have the same definition of Button style, TextBlock style, etc with different property values. Here an example:
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>
There is a way to achieve what I want to do ? Thank you in advance.
We end up to do something like this:
defining a ResourcesDictionary in App.xaml with all the CustomStyles
we make a server request that decides which custom style has to be loaded
using this piece of code Application.Current.Resources[CustomStyleVariable];
we load the whole style in a Style object.
We haven't found any better solution yet but, it seems to work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With