我在 WPF .Net 6 中作業我有一個 Master.exe 應用程式和許多 DLL,每個 DLL 都包含每個物體的功能:Customers.dll | Bookings.dll | Vehicles.dll 等。在每個 DLL 中,我都有 WPF/XAML 視窗、視圖模型、模型等,就像一個完整且獨立的迷你應用程式。
我還創建了一個 Base.dll,其中包含模型和視圖模型繼承的抽象類。這適用于所有 dll 之間的一些共享代碼。
同樣,我想要在所有 XAML 視窗中統一樣式的一站式商店。
現在的問題是;我可以在 Base.dll 中擁有其他 dll 中的所有 XAML 視窗使用的 XAML 資源和樣式嗎?
uj5u.com熱心網友回復:
當然。創建一個WPF Custom Control Library專案并在該專案的一個或多個資源字典中定義您常用的 XAML 資源,例如:
<!-- Dictionary1.xaml in WpfControlLibrary1.dll: -->
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<SolidColorBrush x:Key="CommonBrush" Color="Red" />
</ResourceDictionary>
然后從你打算使用公共資源的專案中添加對該專案的參考并合并資源字典:
<ResourceDictionary>
<Style x:Key="ButtonStyle" TargetType="Button">
<Setter Property="Foreground" Value="{StaticResource CommonBrush}" />
</Style>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/WpfControlLibrary1;component/Dictionary1.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/424216.html
