Unanswered TemplateBinding bug?

  • Tuesday, September 19, 2006 7:16 PM
     
     

    What's the difference between
    {TemplateBinding Foreground}
    and
    {Binding Path=Foreground, RelativeSource={RelativeSource TemplatedParent}}
    ?

    Why does code below throw
    {"Cannot convert the value in attribute 'Value' to object of type ''.  Error at object 'System.Windows.Setter'."}
    ?
    I'm using June CTP 6.0.5456.3.0.

    <Window ...>
        <Window.Resources>
            <Style TargetType="{x:Type Button}">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type Button}">
                            <Border Name="Border" Background="{TemplateBinding Background}"/>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsPressed" Value="true">
                                    <Setter TargetName="Border" Property="Background"
                                        Value="{TemplateBinding Foreground}"/>  <!--        Here        -->
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </Window.Resources>
        <Button Background="Green" Foreground="Red">Click Me</Button>
    </Window>

All Replies

  • Wednesday, September 20, 2006 12:46 AM
     
     

    TemplateBinding is a lightweight, but less functional, version of a Binding with a RelativeSource of TemplatedParent.  One of the things that a TemplateBinding can't do is work within the ControlTemplate.Triggers; TemplateBinding only works within the template content (for example the Border in this case).

    So the {Binding} that you're using is the right solution.