0

I am creating a mini-game where I need to change background image of some elements when the user presses specific keys on the keyboard.

I tried this,

<Style.Triggers>
    <Trigger Property="IsPressed" Value="True">
       <Setter Property="Background" Value="SlateGray" />
       <Setter Property="Foreground" Value="White"></Setter>
    </Trigger>
</Style.Triggers>

And that,


    <Button Content="Content" Background="Red">
            <Button.Triggers>
                <EventTrigger RoutedEvent="MouseEnter">
                    <BeginStoryboard>
                        <Storyboard>
                            <ColorAnimation Storyboard.TargetProperty="(Button.Background).(SolidColorBrush.Color)" To="CadetBlue"/>
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
            </Button.Triggers>
        </Button>

but it works only with colors, I can't change image source. How I can change image on button when clicked?

Themelis
  • 4,048
  • 2
  • 21
  • 45
SUSL1K
  • 1
  • 1
  • Before thinking about changing an image, you should first know how to set an image, how do you "put" an image in the button? – The One Feb 07 '20 at 21:19
  • I do it by constructor in visual studio, I just create a border, and set background image with command image brush – SUSL1K Feb 08 '20 at 12:51
  • I don't understand where I should create this action, in xaml, or cs file with keydown command. When I try to change property ImageSource, VS says to me that he can't convert windows media to string, I will add some code here for better understanding of problem what I talking about. – SUSL1K Feb 08 '20 at 12:56
  • Does this answer your question? [WPF Change button background image when clicked](https://stackoverflow.com/questions/16319063/wpf-change-button-background-image-when-clicked) – ΩmegaMan Feb 10 '20 at 20:00

0 Answers0