views:

311

answers:

2

I'm using a style in my XAML for a label:

<Style x:Key="TreatEye" TargetType="Label">
        <Setter Property="Foreground" Value="#d1d1d1" />
        <Setter Property="FontWeight" Value="Bold" />
        <Setter Property="FontSize" Value="30" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Label">
                    <Canvas>                            
                        <TextBlock x:Name="retreatText" Canvas.Left="80" Canvas.Top="5" FontSize="16"  Text="Retreatment"/>                                                        
                        <TextBlock x:Name="bioinsulatorText" Canvas.Left="21" Canvas.Top="33" Text="Bioinsulator" />
                        <TextBlock x:Name="kxlText" Canvas.Left="21" Canvas.Top="70" Text="KXL Kit" />
                    </Canvas>
...

The problem I'm seeing is that the FontSize property of "reatreatText" is not overridden from the setter value of 30. This builds fine, but the end display has "reatreatText" as size 30. Why is this value not overridden?

Thanks in advance.

+1  A: 

Sorry, but I tried your code inside Kaxaml and works as expected:

<Page
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&gt;
  <Page.Resources>
  <Style x:Key="TreatEye" TargetType="Label">
        <Setter Property="Foreground" Value="#d1d1d1" />
        <Setter Property="FontWeight" Value="Bold" />
        <Setter Property="FontSize" Value="30" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Label">
                    <Canvas>                            
                        <TextBlock x:Name="retreatText" Canvas.Left="80" Canvas.Top="5" FontSize="16" Text="Retreatment"/>                                                        
                        <TextBlock x:Name="bioinsulatorText" Canvas.Left="21" Canvas.Top="33" Text="Bioinsulator" />
                        <TextBlock x:Name="kxlText" Canvas.Left="21" Canvas.Top="70" Text="KXL Kit" />
                    </Canvas>
                </ControlTemplate>
        </Setter.Value>                
      </Setter>
     </Style>
    </Page.Resources>

  <Grid>  
    <Label Style="{StaticResource TreatEye}">Ejemplo</Label>
  </Grid>
</Page>

Result:

alt text

Eduardo Molteni
You are right! After running the application, it displays properly. The problem is with the Visual Studio XAML interpreter that I'm using for development. It is not interpreting the new font size properly.
Tim
A: 

You need to set a TemplateBinding on the TextBlock.

<TextBlock x:Name="retreatText"
           Canvas.Left="80" 
           Canvas.Top="5" 
           FontSize="{TemplateBinding FontSize}" 
           Text="Retreatment"/> 

That's how the setter properties get propogated to the internal structure.

SergioL
Oops. Misread the question. Explicitly setting the size on the TextBlock should have fixed the size at 16.
SergioL