Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Using a WPF control template from a program library in a WPF project

I have a program library in which I have control templates for WPF controls. Now I want to include or use this program library as a .dll in another WPF project.
Is it possible to use these control templates from the library in the XAML of the WPF project?

If yes, how do I do that?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

  • Define your control templates in a resource dictionary in a WPF Class Library or similar

  • Add a reference to the class library from the WPF application project

  • Reference the resource dictionary using a pack URI in the App.xaml.cs class of the WPF application:

      <Application x:Class="WpfApp1.App"
                   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                   StartupUri="MainWindow.xaml">
          <Application.Resources>
              <ResourceDictionary>
                  <ResourceDictionary.MergedDictionaries>
                      <ResourceDictionary Source="pack://application:,,,/YourClassLibrary;component/YourResourceDictionary.xaml"
                  </ResourceDictionary.MergedDictionaries>
              </ResourceDictionary>
          </Application.Resources>
      </Application>
    

You should then be able to reference any resource in the resource dictionary in the class library as usual.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading