如何使全局可用样式无需App.xaml

问题描述:

我有一个类库,我正在为包含WPF控件元素的AutoCAD插件创建。我想为这些元素添加一个主题,所以我添加了Nuget的WPFThemes.DarkBlend包。如何使全局可用样式无需App.xaml

为了财产利用的主题,你应该将样式参考添加到您的App.xaml文件,如下所示:

<Application 
... 
<Application.Resources> 
    <ResourceDictionary> 
     <ResourceDictionary.MergedDictionaries> 
      <ResourceDictionary Source="Themes\Styles.xaml” /> 
     </ResourceDictionary.MergedDictionaries> 
    </ResourceDictionary> 
</Application.Resources> 

现在不幸的是,因为这只是一个类库,我没有用于添加此代码的App.xaml文件。我能够使用我的Window.Resources,但是这样做恐怕引用中的样式不会暴露给Window元素。这是因为窗口不在自己的资源范围内?下面是显示了我目前的状况的图像:

The style is not available to the Window control element

谢谢!

创建X后:在被称为“DarkWindow”风格的关键,我发现,我能直接在PluginWindow.xaml窗口属性应用的样式是这样的:

<Window Style="{DynamicResource DarkWindow}" />