views:

318

answers:

0

So, everywhere I read you can embed a style on a ContentPresenter.Resources and it will automatically apply it to any object that are of the TargetType. So I have the code below.

Simple. But it does not work. Cannot figure this one. Any help??

<UserControl.Resources>
 <Style TargetType="TextBox" x:Key="MyStyle">            
        <Setter Property="Background" Value="Yellow" />
    </Style>
    <ControlTemplate x:Key="MyTemplate" TargetType="HeaderedContentControl">
  <Grid>
   <Border Background="Gray" />
   <Grid>
    <Grid.ColumnDefinitions>
     <ColumnDefinition/>
     <ColumnDefinition/>
    </Grid.ColumnDefinitions>
    <ContentPresenter Grid.Column="0" ContentSource="Header" Margin="5"/>
    <ContentPresenter Grid.Column="1" ContentSource="Content" Margin="2">
     <ContentPresenter.Resources>
                        <Style TargetType="TextBox" BasedOn="{StaticResource MyStyle}"/>
                    </ContentPresenter.Resources>
    </ContentPresenter>
   </Grid>
  </Grid>
 </ControlTemplate>
</UserControl.Resources>

<Grid>
 <HeaderedContentControl Header="FieldName:" Template="{StaticResource MyTemplate}">
  <TextBox Text="If this worked I should be Yellow." />
 </HeaderedContentControl>
</Grid>