tags:

views:

2086

answers:

1

I have the following hierachy:

public class A
{
  protected class B
  {
  }
}

And I've tried to define a default style in the following ways (inside generic.xaml):

<Style TargetType="local:A+B">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="local:A+B">
                <Grid/>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

<Style TargetType="local:A.B">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="local:A.B">
                <Grid/>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

<Style TargetType="local:B">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="local:B">
                <Grid/>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

Does anyone know the correct syntax?

+1  A: 

I don't believe inherited styling is supported as it is in CSS. You can only create a style for a specific target type. Then on the instance you need to nominate the style.

However you are using the generic.xaml file (now under themes/generic.xaml) which applies the default style for a specific target type. So if you need to target contained class B you would need to either define the style of B or include it under A through public properties.

Craig Nicholson
Correct. In general, you shouldn't consider the idea of templates in a hierarchy: you should have a unique template for each control's DefaultStyleKey, etc.
Jeff Wilcox