简体   繁体   English

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

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

I like to change Windows WPF app into .dll library. 我想将Windows WPF应用程序更改为.dll库。 In windows App.xaml directory I have defined "Application.Resources". 在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>

But because in dll library is no App.xaml file, where now to put these code? 但是因为在dll库中没有App.xaml文件,现在将这些代码放在哪里? Add to my "dll-project" new "Resource Dictionary" file? 将新的“资源字典”文件添加到我的“ dll-project”文件中吗? But is this equivalent with "Application.Resources"? 但这等同于“ Application.Resources”吗?

Please for help or any example. 请寻求帮助或任何示例。 If any your have any question, please ask. 如果您有任何疑问,请询问。

In the dll project, add a resource dictionary. 在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>

In the application that uses the dll, in the app.xaml, add the resource dictionary. 在使用dll的应用程序的app.xaml中,添加资源字典。 In the example below, the resource dictionary is in the MyDll project with a path of MyDllSubFolder/MyResourceDictionary.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