Viking
Viking

Reputation: 303

WPF/XAML Button.Template

I'm a bit puzzled. It's not a big problem, but does anyone have a explanation to why this

<Button Command="{Binding CancelButtonClickCommand}" DockPanel.Dock="Right" Height="16" Width="16">
<Button.Template>
    <ControlTemplate>
        <Grid Background="{Binding CancelImage}"/>
    </ControlTemplate>
</Button.Template>

works, when this

<Button Command="{Binding CheckButtonClickCommand}" DockPanel.Dock="Left" Height="16" Width="16">
<Button.Template>
    <ControlTemplate>
        <Image Source="{Binding CheckImage}"/>
    </ControlTemplate>
</Button.Template>

dosen't? The difference being that I use a <Grid Background="{Binding CancelImage}"/> in the first, and a <Image Source="{Binding CheckImage}"/> in the one that dosen't work. In the latter the image isn't visible, and I don't even Command isn't even called.

Thanks a lot in advance /C

Upvotes: 1

Views: 64

Answers (1)

Lennart
Lennart

Reputation: 10354

Grid.Background binds to a Brush type, while Image.Source requires an ImageSource. The easiest way to solve that would be to expose the Brush's ImageSource property in your CheckImage binding. If that's not possible you could also attach a converter to the Image.Source binding and return an ImageSource from the brush you're binding to.

Upvotes: 2

Related Questions