WPF:当我将代码移动到另一个DLL时,不再调用OnApplyTemplate

JiB*_*evé 4 wpf

让我们试着清楚地解释一下.

我有一个自定义控件作为WPF应用程序构建,它工作正常.我已将所有代码移动到外部DLL中.在此更改之后,当我加载应用程序时,不再调用OnApplyTemplate()方法,并且不会呈现控件

  • 我尝试使用Generic.xaml文件进入DLL的根目录中的主题目录(带有大写字母T),该目录具有控件和/或主题目录到StartUp项目中.
  • 如果这个信息很重要,那么我找到了控件:http://www.codeproject.com/KB/WPF/WPFOutlookCalendar.aspx
  • 项目的设置是
    • 输出类型:类库
    • 目标框架:.Net框架4
  • 我已经创建了一个简单的DLL项目,并且我手动添加了引用

你对这个解决方案有什么想法吗?

提前致谢...

Chr*_*ris 7

标准Wpf Applicaton和WPF自定义控件库之间的主要区别是以下代码行.

[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page, 
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page, 
// app, or any theme specific resource dictionaries)
)]
Run Code Online (Sandbox Code Playgroud)

将这些代码行添加到您的程序集应该可以修复您的错误.