Unable to set style for path in resource dictionary

I am creating a style for the Resource dictionary in a resource, as shown below:

<Style x:Key="HeaderPathStyle" TargetType="Path">
        <Setter Property="Opacity" Value="0.8"/>
        <Setter Property="HorizontalAlignment" Value="Stretch"/>
        <Setter Property="VerticalAlignment" Value="Stretch"/>
        <Setter Property="Stretch" Value="Fill"/>
        <Setter Property="StrokeThickness" Value="0.5"/>
        <Setter Property="Data" Value="M12.5,7 C47.333332,7 115.85664,7 117,7 C118.14336,7 122.1255,6.7291665 122.25,12 C122.3745,17.270834 122.25,18.333334 122.25,21.5 L12.5,21.5 z"/>
        <Setter Property="Fill">
            <Setter.Value>
                <RadialGradientBrush GradientOrigin="0.699000000953674,0.792999982833862">
                    <RadialGradientBrush.RelativeTransform>
                        <TransformGroup>
                            <ScaleTransform CenterX="0.5" CenterY="0.5" ScaleX="1.4" ScaleY="2.188"/>
                            <SkewTransform CenterX="0.5" CenterY="0.5"/>
                            <RotateTransform CenterX="0.5" CenterY="0.5"/>
                            <TranslateTransform X="0.017" Y="0.009"/>
                        </TransformGroup>
                    </RadialGradientBrush.RelativeTransform>
                    <GradientStop Color="#FF6C6C8E" Offset="1"/>
                    <GradientStop Color="#FFADD8E6" Offset="0"/>
                </RadialGradientBrush>
            </Setter.Value>
        </Setter>
    </Style>

Then use its usercontrol as shown below:

 <Path Style="{StaticResource HeaderPathStyle}"/>

But I get an error. If I installed Path in the xaml user control directly with the same parameter, there was no error. How to fix it?

+3
source share
1 answer

You cannot just create a resource dictionary and expect all the resources available there to be available. If you want to create a resource accessible from any UserControl, put this resource in App.xaml in the element <Application.Resources>.

App.Xaml , , , - , .xaml: -

<Application.Resources>
  <ResourceDictionary>
    <ResourceDictionary.MergedDictionaries>
       <ResourceDictionary Source="YourDictionaryFile.xaml" />
    </ResourceDictionary.MergedDictionaries>
  </ResourceDictionary>
</Application.Resources>
+1

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


All Articles