<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="WpfApplication1.EventSetterDemo"
Title="EventSetter Demo">
<Window.Resources>
<Style TargetType="{x:Type Button}">
<EventSetter Event="Click" Handler="ButtonOnClick" />
</Style>
</Window.Resources>
<StackPanel>
<Button>Button 1</Button>
<Button>Button 2</Button>
<Button>Button 3</Button>
</StackPanel>
</Window>
//File:Window.xaml.vb
Imports System
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Input
Imports System.Windows.Media
Namespace WpfApplication1
Public Partial Class EventSetterDemo
Inherits Window
Public Sub New()
InitializeComponent()
End Sub
Private Sub ButtonOnClick(sender As Object, args As RoutedEventArgs)
Dim btn As Button = TryCast(args.Source, Button)
Console.WriteLine(btn.Content)
End Sub
End Class
End Namespace
|