Prince OfThief
Prince OfThief

Reputation: 6423

WPF : How to assign click event to the form

How to assign Click event in this? I want to do something when mouse click on this window. It's doesn't have Click properties in both Window and 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>

Upvotes: 6

Views: 23988

Answers (2)

Zain Shaikh
Zain Shaikh

Reputation: 6043

you might want to add MouseLeftButtonDown="Window_MouseLeftButtonDown" on your <Window> element.

and add following in the code-behind file.

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

Upvotes: 10

Fr&#233;d&#233;ric Hamidi
Fr&#233;d&#233;ric Hamidi

Reputation: 262939

You could handle the MouseLeftButtonUp event instead.

Upvotes: 15

Related Questions