Binding a RoutedEvent for the "Click" event of static buttons contained in a StackPanel is easy. The RoutedEventArgs will contain the button as the e.Source of the event.
XAML:
<StackPanel Grid.Column="1" Button.Click="RoutedEventHandler">
<Button Name="btn1" Content="btn1" />
<Button Name="btn2" Content="btn2" />
</StackPanel>
Code Behind:
private void RoutedEventHandler(object sender, RoutedEventArgs e)
{
MessageBox.Show(((FrameworkElement)e.Source).Name);
}
However - handling routed events with "ListViewItem.MouseDoubleClick" will result the ListView container object in the e.Source, instead of the expected ListViewItem object.
XAML:
<ListView Name="lbAnecdotes"
ListViewItem.MouseDoubleClick="RoutedEventHandler">
<ListView.ItemTemplate >
<DataTemplate>
<WrapPanel >
<TextBlock Text="{Binding Path=Name}" />
</WrapPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView >
Can you explain the inconsistency?
ListView
, you get the sameListView
as youre.Source
? You can always refer toe.OriginalSource
if you want the original source. – Vanlalhriatae.Source
?TextBlock
,WrapPanel
? – Anatoliy Nikolaev