Cast event sender to a control
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="WpfApplication1.IncludeApplicationDefinition.MyWindow"
Title="Include Application Definition"
SizeToContent="WidthAndHeight"
ResizeMode="CanMinimize">
<Button HorizontalAlignment="Center" VerticalAlignment="Center" Margin="1.5in" Click="ButtonOnClick">
Click
</Button>
</Window>
//File:Window.xaml.vb
Imports System
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Input
Namespace WpfApplication1.IncludeApplicationDefinition
Public Partial Class MyWindow
Inherits Window
Public Sub New()
InitializeComponent()
End Sub
Private Sub ButtonOnClick(sender As Object, args As RoutedEventArgs)
Dim btn As Button = TryCast(sender, Button)
MessageBox.Show(Convert.ToString(btn.Content) & "' has been clicked.")
End Sub
End Class
End Namespace
Related examples in the same category