views:

62

answers:

1

If I have a Style inside Generic.xaml and I want to reference a style within the SAME Generic.xaml file why does it not work?

<Style TargetType="{x:Type w:SomeControlIWantToStyle}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type w:SomeControlIWantToStyle}">
                    ...
                    <TextBlock Text="{DynamicResource SomeStyle}" />

                    ...

<Style x:Key="SomeStyle" ... />

I am unable to reference the "SomeStyle" from within the ControlTemplate!

Any ideas?

+2  A: 

please put the

<Style x:Key="SomeStyle" ... /> 

style on top of this style

<Style TargetType="{x:Type w:SomeControlIWantToStyle}"> 
    <Setter Property="Template"> 
        <Setter.Value> 
            <ControlTemplate TargetType="{x:Type w:SomeControlIWantToStyle}"> 
                ... 
                <TextBlock Text="{DynamicResource SomeStyle}" /> 

                ... 

just maintain the hierarchy. If you want to call the style just declare the style above the calling style.

Kishore Kumar