簡體   English   中英

WPF控件庫樣式

[英]WPF Style for Control Library

我有一個庫( Styles.DLL ),其中包含鍵控WPF Styles的集合。

我有一個類庫( Module.DLL ),其中包含許多Windows和可以在各種應用程序之間共享的UserControls 我使用Styles.DLL定義的鍵控Styles為這些WindowsUserControls例如ButtonComboBox上使用的各種Controls創建隱式Styles

然后,我有了一個應用程序( App.EXE ),其中使用了Module.DLL定義的Windows 我從Styles.DLLApp.xamlApp.EXE合並所需的ResourceDictionaries

所有這一切。


我的問題是: 如何才能從托管應用程序中的App.xaml中刪除合並的字典,並將其包含在Module.DLL中,而不必將字典合並到每個Window的資源中?

我想我正在尋找app.xaml文件之類的東西,但在尋找類庫...

我使用一種清除當前詞典並合並所需詞典的方法。 實際上,必須在方法調用時在內部設置“清除”,這是一個示例:

    void AddResourceDictionary(string source)
    {
        ResourceDictionary resourceDictionary = Application.LoadComponent(new Uri(source, UriKind.RelativeOrAbsolute)) as ResourceDictionary;
        Application.Current.Resources.MergedDictionaries.Add(resourceDictionary);
    }

實施自定義主題/皮膚/資源:

        private void ThemeNameHere()
    {
        Application.Current.Resources.Clear();

        AddResourceDictionary("Computar.Wpf;component/Style/MyStyle.xaml");
        ....

    }

這非常有幫助!

我找不到僅使用XAML解決此問題的方法。 我的解決方案是使用以下代碼將所需的ResourceDictionaries合並到代碼中的Application對象中:

Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary
{
    Source = new Uri(@"pack://application:,,,/Styles.DLL;component/Styles.xaml")
});

希望這對遇到類似問題的人有所幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM