1

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.

esispaned
  • 283
  • 5
  • 20

1 Answers1

3

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>
J.H.
  • 4,232
  • 1
  • 18
  • 16