Now I connect the styles to the window like this:

<Window x:Class="BrainTrain.Windows.WorkWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:BrainTrain.Windows" mc:Ignorable="d" Title="WorkWindow" Height="482"> <Window.Resources> <Style TargetType="Ellipse"> <Setter Property="Stroke" Value="Black" /> </Style> </Window.Resources> </Window> 

Everything is fine, but when there are more styles, it will be inconvenient to work with them. From this follows the question. How to connect styles rendered in a separate file? I have created it, but I don’t understand where and what to register.

Here is the App.xaml

 <Application x:Class="BrainTrain.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Application.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="Localization/lang.xaml" /><!--Localization File--> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Application.Resources> </Application> 

Here is the path relative to the file where I want resources.

 ViewResources/WorkWindowStyles.xaml 
  • and what's the problem? - EvgeniyZ

1 answer 1

If you open the MSDN documentation , you will see that ResourceDictionary.MergedDictionaries is a Collection<ResourceDictionary> (you can see the same thing if you put the cursor on the right word and press F12 in Visual Studio), then you just need to add all the necessary resource dictionaries. to this collection:

 <Application ...> <Application.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="Localization/lang.xaml"/> <ResourceDictionary Source="ViewResources/WorkWindowStyles.xaml"/> <!--etc--> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Application.Resources> </Application> 

More reading on the topic: Consolidated resource dictionaries