XAML Review
www.shaxam.com

XAML Events Element

Posted in Software

Elements deriving from UIElement inherit a set of common events. Events are used in XAML to specify the codebehind handler that will be executed when the specified event is raised. All events can be assigned a codebehind handler using the following syntax:

Elements specifying a codebehind handler must declare the Name attribute in order to be referenced in the codebehind class.

C# implementation of event handlers
public partial class MouseEnterMouseLeave
{
void MouseEnterHandler (object sender, MouseEventArgs e)
{
MyButton .Background=Brushes.Red;
MyButton .Content=”Mouse is over me “;
}
void MouseLeaveHandler (object sender, MouseEventArgs e)
{
MyButton .Background=Brushes.White;
MyButton .Content=”Mouse is not over me “;
}
}

VisualBasic implementation of event handlers
Partial Public Class MouseEnterMouseLeave
Sub MouseEnterHandler (ByVal sender as Object, ByVal e As MouseEventArgs
MyButton .Background = Brushes.Red
MyButton .Content = “Mouse is over me ”
End Sub
Sub MouseLeaveHandler (ByVal sender As Object, ByVal e as MouseEventArgs
MyButton .Background = Brushes.White
MyButton .Content = “Mouse is not over me ”
End Sub
End Class

XAML declaration of event handlers for Button
xmlns="http://schemas.microsoft.com/winfx/avalon/2005"
xmlns:x="http://schemas.microsoft.com/winfx/xaml/2005"
x :Class="ButtonExample.MouseEnterMouseLeave "
Content="Mouse is not over me "
MouseEnter="MouseEnterHandler "
MouseLeave="MouseLeaveHandler "
Name="MyButton " />

The following events are common to all UIElement-derived elements. Events specific to the element are listed with the element description.

DragEnter
DragLeave
DragOver
Drop
GotFocus
IsVisibleChanged
IsEnableChanged
IsFocusChanged
KeyUp
KeyDown
LayoutUpdated
LostFocus
MouseEnter
MouseLeave
MouseMove
MouseLeftButtonDown
MouseLeftButtonUp
MouseRightButtonDown
MouseRightButtonUp
PreviewDragOver
PreviewDragEnter
PreviewDragLeave
PreviewDrop
PreviewKeyUp
PreviewKeyDown
PreviewMouseLeftButtonDown
PreviewMouseLeftButtonUp
PreviewMouseRightButtonDown
PreviewMouseRightButtonUp
PreviewMouseMove

Thanks for Reading.