Do event based on button name
<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="150" Width="250">
<StackPanel>
<StackPanel>
<StackPanel.Resources>
<Style TargetType="{x:Type Button}">
<Setter Property="Margin" Value="2" />
<EventSetter Event="Click" Handler="btnShowPopup_Click" />
</Style>
</StackPanel.Resources>
<Button Content="Show Popup" Name="btnShowPopup" />
<Button Content="Fade Popup" Name="btnFadePopup" />
<Button Content="Scroll Popup" Name="btnScrollPopup" />
<Button Content="Slide Popup" Name="btnSlidePopup" />
</StackPanel>
</StackPanel>
</Window>
//File:Window.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Controls.Primitives;
namespace WpfApplication1
{
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
private void btnShowPopup_Click(object sender, RoutedEventArgs e)
{
if (sender == btnFadePopup)
{
Console.WriteLine("fade");
}
else if (sender == btnScrollPopup)
{
Console.WriteLine("scroll");
}
else if (sender == btnSlidePopup)
{
Console.WriteLine("slide");
}
else
{
Console.WriteLine("else");
}
}
}
}
Related examples in the same category