我有一個程式庫,其中有 WPF 控制元件的控制元件模板。現在我想在另一個 WPF 專案中包含或使用這個程式庫作為 .dll。是否可以在 WPF 專案的 XAML 中使用庫中的這些控制元件模板?
如果是,我該怎么做?
uj5u.com熱心網友回復:
在 WPF 類別庫或類似的資源字典中定義控制元件模板
從 WPF 應用程式專案中添加對類別庫的參考
App.xaml.cs在 WPF 應用程式的類中使用包 URI 參考資源字典:<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>
然后,您應該能夠像往常一樣參考類別庫中資源字典中的任何資源。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/489032.html
