我将我的应用程序资源存放在一个单独的DLL中,并使用类似于以下内容在App.xaml中引用它们:
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MyThemesAssembly;component/Themes/Generic.xaml"/>
</ResourceDictionary.MergedDictionaries>
当我编辑在主EXE项目中的窗口时,VS2010设计器不会识别其他程序集中的任何资源,因此我看不到任何应用的样式(这并不是一个真正的问题,因为我总是在XAML视图中工作)。然而,Resharper也不认识这些外部资源名称,在我编辑XAML时会出现许多下划线标记。
我发现,可以通过在每个窗口和用户控件中包含上述XAML来修复VS设计器和Resharper,但这会对内存和/或性能产生不良影响吗?每个窗口都会有一个单独的资源副本吗?
public class MyUserControlBase : UserControl { public MyUserControlBase() { if (DesignerProperties.GetIsInDesignMode(this)) LoadExternalDictionariesExplicitlyHere(); ...
) - VladHelpers.LoadDictionariesIfInDesignMode(this)
)似乎比 XAML 中的多行代码更简洁 :) - VladApp.xaml
定义的MergedDictionaries
,但是您需要将MyThemesAssembly
作为项目引用,而不是二进制引用... - controlflow