简体   繁体   中英

making WPF dll, where to put Application.Resources?

I like to change Windows WPF app into .dll library. In windows App.xaml directory I have defined "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? Add to my "dll-project" new "Resource Dictionary" file? But is this equivalent with "Application.Resources"?

Please for help or any example. If any your have any question, please ask.

In the dll project, add a resource dictionary.

<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. In the example below, the resource dictionary is in the MyDll project with a path of 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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM