How to use styles defined in ResourceDictionary

I have several common styles, and I want to share them on several pages of my Windows 8.1 application.

I know what I can achieve with the option of merging dictionaries , but I have no idea how to use the styles defined in the dictionary.

I tried this:

<Page.Resources>
<ResourceDictionary x:Key="lol">
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="Themes/Generic.xaml" />
        <ResourceDictionary>
            <Style x:Key="TextViewAllStyle" TargetType="TextBlock">
            </Style>
        </ResourceDictionary>
    </ResourceDictionary.MergedDictionaries>
    <Style x:Key="TextViewAllStyle2" TargetType="TextBlock">
    </Style>
</ResourceDictionary>
<Style x:Key="TextViewAllStyle3" TargetType="TextBlock">
</Style>
</Page.Resources>

But my Visual Studio only sees the third ...

<TextBlock Style="{StaticResource ResourceKey=TextViewAllStyle3}"/>
+4
source share
1 answer

add the following tag to your App.Xaml:

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            -- reference your dictionaries here --
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>

each dictionary can be added along its full path:

<ResourceDictionary Source="pack://application:,,,/MySolution.MyProject;component/Theme/Generic.xaml"/>

if in the same project by its relative path:

<ResourceDictionary Source="Themes\Generic.xaml"/>

or defined in the line:

<Style x:Key="TextViewAllStyle" TargetType="TextBlock">
</Style>
+11
source

Source: https://habr.com/ru/post/1529546/


All Articles