WPF:当我将代码移动到另一个 DLL 时不再调用 OnApplyTemplate [英] WPF: OnApplyTemplate is not called anymore when I moved code into another DLL

查看:21
本文介绍了WPF:当我将代码移动到另一个 DLL 时不再调用 OnApplyTemplate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们试着解释清楚.

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

I've got a custom control built as a WPF application and it works fine. I've moved all the code into a external DLL. After this change, when I load the application, the method OnApplyTemplate() is not called any more and the control is not rendered either

  • 我尝试将 Generic.xaml 文件放入 DLL 根目录中的 Themes 目录(大写 T)在 StartUp 项目中拥有控制和/或 Themes 目录.
  • 如果此信息很重要,我在这里找到了控件:http://www.codeproject.com/KB/WPF/WPFOutlookCalendar.aspx
  • 项目的设置是
    • 输出类型:类库
    • 目标框架:.Net Framework 4
    • I've try with Generic.xaml file is into a Themes directory (with capital T) in the root of the DLL which has the control and/or a Themes directory into the StartUp project.
    • If this info is important here's where I've found the control: http://www.codeproject.com/KB/WPF/WPFOutlookCalendar.aspx
    • The settings of the project is
      • Output type: Class Library
      • Target framework: .Net Framework 4

      您对解决方案有什么想法吗?

      Do you have any idea about the solution?

      提前致谢...

      推荐答案

      标准 Wpf 应用程序和 WPF 自定义控件库之间的主要区别在于以下几行代码.

      The main difference between a standard Wpf Applicaton and a WPF Custom Control library are the following lines of code.

      [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)
      )]
      

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

      Adding these lines of code to your Assembly should fix your bug.

      这篇关于WPF:当我将代码移动到另一个 DLL 时不再调用 OnApplyTemplate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆