none
Template Binding Problem RRS feed

  • Question

  • Hi,

    I'm trying to make a template for the Thumb control. I have a ViewBox in the template, and want to bind the Angle of RotateTransform of the ViewBox to one of the Thumb control properties, eg FontSize! So I could change tha Angle of that ViewBox (in the template) with the FontSize property of my Thumb control. But When I change the FontSize property nothing happen! Why?

    Regards,
    Parham.
    Thursday, February 21, 2008 1:46 PM

Answers

  • The binding should be something like the following:

    Code Snippet
    <RotateTransform Angle="{Binding Path=FontSize, RelativeSource={RelativeSource TemplatedParent}}"/>

    Note that TemplateBinding is a lightweight "binding", it doesn't support inheritance context as Binding does.

    Hope this helps
    Monday, February 25, 2008 5:41 AM

All replies

  • Hi,

     

    Could you please post the XAML that you use?

     

    Thursday, February 21, 2008 2:27 PM
  • Here is the code:

    Code Snippet

        <Style x:Key="TriangleThumbStyleToRight" TargetType="{x:Type Thumb}">
            <Setter Property="Stylus.IsPressAndHoldEnabled" Value="false"/>
            <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Thumb}">
                        <Grid Width="Auto" Height="Auto">
                            <Viewbox Stretch="Uniform" RenderTransformOrigin="0.5,0.5">
                                <Viewbox.RenderTransform>
                                    <TransformGroup>
                                        <ScaleTransform ScaleX="1" ScaleY="1"/>
                                        <SkewTransform AngleX="0" AngleY="0"/>
                                        <RotateTransform Angle="{TemplateBinding FontSize}"/>
                                        <TranslateTransform X="0" Y="0"/>
                                    </TransformGroup>
                                </Viewbox.RenderTransform>
                                <Path x:Name="Path" Stretch="Fill" StrokeLineJoin="Round" Stroke="{TemplateBinding BorderBrush}" Fill="{TemplateBinding Background}" Data="F1 M 313.444,67.8889L 227.222,23.5001L 243.34,67.8745L 227.222,112.222L 313.444,67.8889 Z " StrokeThickness="2" Width="Auto" Height="Auto"/>
                            </Viewbox>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>


    Thursday, February 21, 2008 3:55 PM
  • The binding should be something like the following:

    Code Snippet
    <RotateTransform Angle="{Binding Path=FontSize, RelativeSource={RelativeSource TemplatedParent}}"/>

    Note that TemplateBinding is a lightweight "binding", it doesn't support inheritance context as Binding does.

    Hope this helps
    Monday, February 25, 2008 5:41 AM