我有一个包含主窗口WPF应用程序刚刚显示MainUserControl,它也包含了App.xaml中与合并的词典:RecourceDictionaries和自定义转换
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources\Styles.xaml"/>
<ResourceDictionary Source="Resources\DataTemplates.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
于是我决定用MainUserControl在另一个项目中,它应该是显示在ElementHost中。不幸的是,它不起作用,因为找不到资源字典中的样式和数据模板。我不知道去解决它了正确的方式,但我决定,我可能会移动代码ResourceDictionaries代码到MainUserControl的资源:
<UserControl.Resources>
<ResourceDictionary>
<!-- the same code -->
</ResourceDictionary>
</UserControl.Resources>
这引起我的转换器我在资源字典使用的错误 - 无法创建未知类型“{clrnamespace:MyApplication.Converters;装配=所有MyApplication} LengthToStringConverter 。我试图通过增加一个资源字典和我的转换器来移动资源字典外的转换器:
<ResourceDictionary>
<con:LengthToStringConverter x:Key="textConverter"/>
<con:DateToTextConverter x:Key="dateConverter"/>
</ResourceDictionary>
这也造成了XAML异常(在“System.Windows.StaticResourceExtension”提供价值引发了异常。)。
所以我在找的是解决转换器问题的方法,这些转换器在资源字典中找不到,或者在另一个项目中使用MainUserControl类来解决问题的另一种方法(它根本找不到资源,也许,有一种方法可以指定它们?)。
最后,我创建了转换器/自定义控件,样式和主要应用独立的组件,并作出后它的工作。 – 2011-01-13 09:52:07