<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="WPF" Height="100" Width="300">
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal">
<Button Click="SharedButtonClickHandler" Height="23" Margin="5"
Name="button1" Width="75">Button _One</Button>
<Button Click="SharedButtonClickHandler" Height="23" Margin="5"
Name="button2" Width="75">Button _Two</Button>
<Button Click="SharedButtonClickHandler" Height="23" Margin="5"
Name="button3" Width="75">Button T_hree</Button>
</StackPanel>
</Window>
//File:Window.xaml.vb
Imports System
Imports System.Windows
Imports System.Windows.Controls
Namespace WpfApplication1
Public Partial Class Window1
Inherits Window
Public Sub New()
InitializeComponent()
End Sub
Private Sub SharedButtonClickHandler(sender As Object, e As RoutedEventArgs)
Dim source As Button = TryCast(e.OriginalSource, Button)
If source IsNot Nothing Then
Dim message As String = [String].Format("{0} was pressed.", source.Content)
MessageBox.Show(message, Title)
End If
End Sub
End Class
End Namespace
|