Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF: OnApplyTemplate is not called anymore when I moved code into another DLL

Tags:

wpf

Let's try to explain it clearly.

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

  • 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
  • I've create a simple DLL project and I've added the references manually

Do you have any idea about the solution?

Thanks in advance...

like image 805
JiBéDoublevé Avatar asked Dec 27 '22 12:12

JiBéDoublevé


2 Answers

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.

like image 57
Chris Avatar answered May 18 '23 16:05

Chris


Thanks to dowhilefor, I've found the solution!

I've recreated a new library as a WPF Custom Control Library and it works.

It is a little overkill to recreate a new project so if someone can explain to me how to reconfigure an existing project, it'd be very nice ;)

like image 39
JiBéDoublevé Avatar answered May 18 '23 16:05

JiBéDoublevé