2

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);
4

1 回答 1

3

我刚刚在 Office 2010 上尝试过这个(实际上使用的是 2007 VSTO 插件,但在 2010 年运行它)并且效果很好。我在 VSTO 项目中引用了一个外部项目的库,我在控件中使用以下 xaml 来链接资源字典。

<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>

否则我会认为这是一个问题,因为您的样式被后来的一些显式或隐式链接的样式覆盖。如果它找不到您引用的程序集,它应该抛出一个示例,因此问题不应该存在。

于 2011-01-27T15:18:52.270 回答