我的项目中有一个CommonResources.xaml,其构建操作为Embedded Resource
。我已使用以下代码将此添加到mycustomcontrol.xaml
。
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/MyApp;Component/Resources/CommonResources.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
这在设计时非常有效,我的风格也会根据需要应用。
但是在运行时我得到以下异常。
A first chance exception of type 'System.Windows.Markup.XamlParseException' occurred in PresentationFramework.dll
Additional information: '/MyApp;Component/Resources/CommonResources.xaml'
value cannot be assigned to property 'Source' of object 'System.Windows.ResourceDictionary'.
Cannot locate resource 'resources/commonresources.xaml'. Error at object
'System.Windows.ResourceDictionary' in markup file
'MyApp;component/application/controls/mycustomcontrol.xaml' Line 18 Position 37.
我不知道为什么这会在运行时失败。有什么想法吗?