WPF: Template Binding in Control template

Posted by Sam on Stack Overflow See other posts from Stack Overflow or by Sam
Published on 2011-01-09T10:47:35Z Indexed on 2011/01/09 10:53 UTC
Read the original article Hit count: 198

Filed under:
|

I have the following control template.

I wish to set the source property for the image control in the control template using Template Binding.

But since this is a control template for button control and the button control doesn't have source property, i can't use TemplateBinding in this case.

<ControlTemplate x:Key="BtnTemplate" TargetType="Button">
        <Border CornerRadius="5"  Margin="15" Cursor="Hand">
            <StackPanel>
                <Image Name="Img" Style="{StaticResource ImageStyle}" Source="temp.jpg" Height="100" Width="100" Margin="5"></Image>
                <Label Content="{TemplateBinding Content}" Background="Transparent" Margin="2"></Label>
            </StackPanel>
        </Border>
    </ControlTemplate>

Since i have to set different images for different instances of button, i can't hardcode the path as well.

Please let me know how to tackle this situation.

© Stack Overflow or respective owner

Related posts about wpf

Related posts about controltemplate