Within my App.xaml I have the following segment:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Assets/Styles.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
I want to be able to override the styling information contained within the Styles.xaml file with styling information fetched via a DomainContext from my Entity Framework connection using RIA services. To this end I have created the following code segment which is in the constructor in App.xaml.cs:
ManagementConsoleDomainContext context = new ManagementConsoleDomainContext();
EntityQuery<Theme> query =
from e in context.GetThemesQuery()
where e.Customer == "Test"
select e;
context.Load(query).Completed += (sender, args) =>
{
Theme t = ((LoadOperation<Theme>)sender).Entities.First();
ResourceDictionary dict = XamlReader.Load(t.Xaml) as ResourceDictionary;
this.Resources.MergedDictionaries.Clear();
this.Resources.MergedDictionaries.Add(dict);
System.Windows.Controls.Theming.ImplicitStyleManager.SetApplyMode(this.LayoutRoot, System.Windows.Controls.Theming.ImplicitStylesApplyMode.OneTime);
System.Windows.Controls.Theming.ImplicitStyleManager.Apply(this.LayoutRoot);
};
The XAML it retrieves is identical however with a few colours changed. The colours on screen are not updated however. I have tried placing the same code into the constructor for the top level UserControl, however again with no joy.
Can anyone give me some pointers on where I'm going wrong?
Cheers!