I am having a button with Image on it as follows:
<Button Width="22" Height="22" Command="{Binding PreviousCommand}">
<Button.Template>
<ControlTemplate>
<Image Source="C:\Users\abcdef\Desktop\Slide-To-Left-Arrow-24.png"></Image>
</ControlTemplate>
</Button.Template>
<Button.InputBindings>
<KeyBinding Key="Up" Command="{Binding PreviousCommand}" Modifiers="Alt+Shift" />
</Button.InputBindings>
</Button>
I want to apply some mouse over effect to recognise button is clickable/focusable. I tried adding trigger as follows but its not working:
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="Black" />
</Trigger>
</ControlTemplate.Triggers>
Its not working. what I need to do? please help me out.
Your control template consists only of an Image at this point, so there is nothing that you can change the background on (through your trigger). If you'd like to add a background change, you'll need to expand your
ControlTemplate
a little. Try something like this:This is just a very simple example of how you can utilize the trigger you've shown above. All this does is add a
Grid
under the image and aMargin
to the image so that part of theGrid
is visible. It then uses theTarget
property of theSetter
to assign theBackground
of theGrid
when the user hovers over the button. You can certainly do much more with yourControlTemplate
to provide other types of visual cues, but hopefully this will get you started.