<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.cs
using System;
using System.Windows;
using System.Windows.Controls;
namespace WpfApplication1
{
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
private void SharedButtonClickHandler(object sender, RoutedEventArgs e)
{
Button source = e.OriginalSource as Button;
if (source != null)
{
string message = String.Format("{0} was pressed.", source.Content);
MessageBox.Show(message, Title);
}
}
}
}