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?
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.