I have a set of styles and brushes defined in the ResourceDictionary that I load as MergedDictionary in the XAML of my top-level control:
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/MyAssembly;component/Styles.xaml"/>
</ResourceDictionary.MergedDictionaries>
I try to replace some of these styles and brushes if necessary, if another XAML file with its own ResourceDictionary exists in XAP. I am trying to combine this dictionary at runtime before InitializeComponent () is called in my user control. For this, I use the following code:
public static class StyleLoader
{
public static void MergeStyle(string xamlUri)
{
try
{
XDocument xaml = XDocument.Load(xamlUri);
ResourceDictionary rd = XamlReader.Load(xaml.ToString()) as ResourceDictionary;
Application.Current.Resources.MergedDictionaries.Add(rd);
}
catch (XmlException ex)
{
}
}
}
, , , . XAML , :
StyleLoader.MergeStyle("/MyAssembly;component/Styles.xaml");
StyleLoader.MergeStyle("BrushReplacements.xaml");
InitializeComponent();
, XAML Blend. - , , Blend, ? !