WPF: how to assign a click event to a form

How to assign a Click event in this? I want to do something by clicking on this window. It does not have click properties in a window or in a canvas.

<Window Loaded="Window_Loaded" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Class="InClassApp.UI.TextNotify" x:Name="Window" Title="TextNotify" Width="400" Height="100" WindowStyle="None" AllowsTransparency="True" Background="Transparent" ShowInTaskbar="False"> <Border CornerRadius="5"> <Border.Background> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="#FFBAFDFF" Offset="0"/> <GradientStop Color="White" Offset="1"/> </LinearGradientBrush> </Border.Background> <Canvas x:Name="LayoutRoot" > ....... </Canvas> </Border> 

+6
wpf canvas mouseclick-event
source share
2 answers

you can add MouseLeftButtonDown="Window_MouseLeftButtonDown" to your <Window> element.

and add the following to the code file.

 private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { // do some stuff here. } 
+6
source share

Instead, you can handle MouseLeftButtonUp .

+12
source share

All Articles