WPF - Canvas_MouseLeftButtonDown event

Hi

I started working with WPF yesterday and ran into some problems. I came to understand that the canvas was equivalent to a panel in WinForms. However, I ran into some difficulties with the 'click' event. MouseLeftButtonDown event. If it is relevant or not, this image and Canvasses are in the UserControl

Image + 3 Canvasses

The above image is mainly related to what I'm having difficulty with. The 3 images you see are one image. The squares you see are different canvases. Depending on what canvas is pressed, I want something else to happen.

I currently have the following code:

<Grid>
    <Canvas Name="canvasTerran"  Height="27" Width="26" Margin="88,106,134,106" MouseLeftButtonDown="canvasTerran_MouseLeftButtonDown" />
    <Canvas Name="canvasZerg" Height="27" Width="26" Margin="117,107,105,107" MouseLeftButtonDown="canvasZerg_MouseLeftButtonDown" />
    <Canvas Name="canvasProtoss" Height="27" Margin="145,107,88,107" MouseLeftButtonDown="canvasProtoss_MouseLeftButtonDown" />
    <Image Name="imageRaces" Height="27" Width="73" Stretch="Fill" Source="pack://application:,,,/Images/Races/Races.png" />
</Grid>

( ), , . , :

 private void canvasTerran_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            MessageBox.Show("lolterran", "lol");

            // image on main window
            // .Source = new BitmapImage(new Uri("pack://application:,,,/" + Constants.RACESPATH + "T.png"));
        }

, , . , WPF, , , , , !

.

+3
2

, . , , .

Background = White Red, , , MouseLeftButtonDown.

+4

, XAML , , .

. , , . , , .

+3

Source: https://habr.com/ru/post/1778489/


All Articles