tags:

views:

32

answers:

1

I create a style for Path in resource dictionary as 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 it usercontrol as below:

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

But I get error. If I set Path in user control xaml directly with same setting, no error. How to fix it?

+1  A: 

You can't just create a Resource Dictionary and expect all resources placed there to accessible immediately. If you want to create a resource that is available from any UserControl then place that resource in the App.xaml in the <Application.Resources> element.

If you'd rather not cluter the App.Xaml with all sorts of resources but still want them to be globally available then using a resource dictionary is the correct approach but then you need to create a reference to that dictionary in the App.xaml:-

<Application.Resources>
  <ResourceDictionary>
    <ResourceDictionary.MergedDictionaries>
       <ResourceDictionary Source="YourDictionaryFile.xaml" />
    </ResourceDictionary.MergedDictionaries>
  </ResourceDictionary>
</Application.Resources>
AnthonyWJones
Thanks. The problem is not because of where I put the style. I have set right place for resource dictionary that already have many other styles working fine.
KentZhou