[英]Custom control styles not working (via Generic.xaml)
對於外部自定義控件庫項目中的標准WPF控件和自定義控件,我有幾種樣式和模板。 對於每個控件,我的\\Themes
文件夾中都有一個ResourceDictionary
,以及一個Generic.xaml
,其中包含所有其他XAML文件的合並字典。
我確保:
Generic.xaml
位於項目根目錄下的Themes\\
文件夾中 Generic.xaml
具有Page
的構建動作 。 Generic.xaml
使用自定義工具標志MSBuild:Compile
。 [assembly: ThemeInfo(ResourceDictionaryLocation.None, ResourceDictionaryLocation.SourceAssembly)]
我試過的
Source="MyControl.xaml"
Source="/MyLibrary;component/Themes/MyControl.xaml"
Source="/MyLibrary;component/Themes/MyControl.xaml"
Source="/pack://application:,,,/Themes/MyControl.xaml"
Source="/pack://application:,,,/MyLibrary;component/Themes/MyControl.xaml"
Generic.xaml
但是,沒有任何效果。 即使我看到訪問Application.Current.Resources
時所有字典都已加載,該應用程序仍然沒有主題。
還值得注意的是,我的大多數控件主題都包含其他動態資源(用於顏色等),這些資源在應用程序啟動時手動加載。
您是否在靜態構造函數中定義了以下代碼?
DefaultStyleKeyProperty.OverrideMetadata(typeof(YourCustomClass),new FrameworkPropertyMetadata(typeof(YourCustomClass))));
不要在資源字典中使用x:key =“ style_name”
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.