Reputation:
We are creating an office ribbon that opens up a WPF window that is stored in another WPF Control library project. That WPF window has some themes attached to it that is stored in a ResourceDictionary that is compiled in a separate project.
However when we load up the WPF window, all the themes from the ResourceDictionary are lost.
We can fix this by manually/forcing the theme on the window itself, but this seems like a bad solution. So my question is: how can I load the theme of the new WPF window from the Office Addin application?
Uri uri = new Uri("/Nov.Presentation.RigDoc.WpfResources;component/Shared.xaml", UriKind.Relative);
Resources.MergedDictionaries.Add(Application.LoadComponent(uri) as ResourceDictionary);
Upvotes: 2
Views: 2707
Reputation: 6216
I just tried this with Office 2010 (actually using a 2007 VSTO Addin but running it in 2010) and it works perfectly. I´ve got an external project´s library referenced in the VSTO project and I use this following xaml in the control to link in the resource dictionary.
<UserControl.Resources>
<ResourceDictionary>
<!-- Link in th general styles -->
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MyAssemblyName;component/MyResourceDictionaryName.xaml" />
</ResourceDictionary.MergedDictionaries>
<!-- Other style... -->
</ResourceDictionary>
</UserControl.Resources>
Otherwise I could think of it being a problem with your styles being overrided by some later explicit or implicitly linked in styles. If it cannot find the assembly you reference it should throw an example so the problem shouldn't be therein.
Upvotes: 3