簡體   English   中英

制作WPF dll,在哪里放置Application.Resources?

[英]making WPF dll, where to put Application.Resources?

我想將Windows WPF應用程序更改為.dll庫。 在Windows App.xaml目錄中,我定義了“ Application.Resources”。

<Application x:Class="WpfApplication13.App"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         StartupUri="MainWindow.xaml">
<Application.Resources>
    <Style TargetType="Control" x:Key="EmptyFocusVisualStyle">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate>

                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</Application.Resources>

但是因為在dll庫中沒有App.xaml文件,現在將這些代碼放在哪里? 將新的“資源字典”文件添加到我的“ dll-project”文件中嗎? 但這等同於“ Application.Resources”嗎?

請尋求幫助或任何示例。 如果您有任何疑問,請詢問。

在dll項目中,添加資源字典。

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Style TargetType="Control" x:Key="EmptyFocusVisualStyle">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate>

                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>

在使用dll的應用程序的app.xaml中,添加資源字典。 在下面的示例中,資源字典位於MyDll項目中,其路徑為MyDllSubFolder / MyResourceDictionary.xaml。

<Application x:Class="WpfApplication13.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="/MyDll;component/MyDllSubFolder/MyResourceDictionary.xaml" />
                    </ResourceDictionary.MergedDictionaries>
                    <Style TargetType="Control" x:Key="AStyleThatIsInTheAppAndNotTheDll">
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </ResourceDictionary>
        </Application.Resources>
</Application>

暫無
暫無

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

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