![](/img/trans.png)
[英]Explicit properties of UserControl are ignored inside Generic.xaml
[英]Is it possible to use Generic.xaml to skin UserControl derived controls?
我有一個僅由UserControl派生的控件組成的控件庫。 我正在使用第三方創建的程序集對控件進行外觀設置。 在常規WPF應用程序項目中,我要做的就是從Application.xaml中的程序集中合並資源字典:
<Application x:Class="Application"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary Source="/ThirdPartyAssembly;component/SomeSkin.xaml" />
</Application.Resources>
</Application>
我嘗試通過將資源字典添加到我的控件庫中的Generica.xaml來實現相同的效果:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/ThirdPartyAssembly;component/SomeSkin.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
但這是行不通的。 從我一直閱讀的內容來看,這種方法似乎僅適用於從Control派生的控件?
我已經嘗試/檢查了以下內容:
<Assembly: ThemeInfo(ResourceDictionaryLocation.None, ResourceDictionaryLocation.SourceAssembly)>
我是否可以不必在資源庫中添加資源字典到我的庫中的每個控件上而對控件進行外觀設置?
最終,我將WPF用戶控件托管在WinForms應用程序中-因此,我無法像在WPF應用程序中使用控件那樣,使用在Application.xaml中設置外觀的明顯方法。
確保Generic.xaml
在正確稱為Resources
最上面的部分UserControl
你在你的窗戶形式托管。
我個人認為主題適用於從Control
派生的任何事物,因此也適用於UserControl
(因為UserControl
本身派生自Control
)。
我已經測試了上面的第1步和第2步,當托管在Windows窗體中時,我的用戶控件完全將它們應用了。
話雖如此,我還沒有嘗試應用任何基於第三方工具(外部程序集)的主題。 所以這是我不確定的事情。
將讓您知道我是否可以在WindowsFormsHost infragistics
(第三方)主題應用於我的用戶控件。 但是關鍵是WindowsFormsHost中最頂層的 UserControl必須引用其中的主題。
如果上述提示不起作用,請分享您的想法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.