I have a XAML listview defined thusly, with events defined on the "PreviewMouseRightButtonUp" and "PreviewMouseLeftButtonUp" events:
<ListView Name="lstItems" DockPanel.Dock="Top" >
<ListView.ItemContainerStyle>
<Style TargetType="{x:Type ListViewItem}" BasedOn="{StaticResource ListViewItemStyle}">
<EventSetter Event="PreviewMouseRightButtonUp"
Handler="OnListViewItemPreviewMouseRightButtonUp" />
<EventSetter Event="PreviewMouseLeftButtonUp"
Handler="OnListViewItemPreviewMouseLeftButtonUp" />
</Style>
</ListView.ItemContainerStyle>
</ListView>
I also have a class, ObjRow, that inherits from UserControl, with a button on it:
<DockPanel LastChildFill="True">
<Button Name="btnOpen" DockPanel.Dock="Left" BorderBrush="Transparent" Style="{StaticResource FolderButton}" IsTabStop="False"/>
</DockPanel>
And finally, in the code-behind of the listview I call a method where I set an event on the button's "Click" event:
foreach (var obj_items in objs)
{
ObjRow item = new ObjRow();
item.btnOpen.Click += new RoutedEventHandler(btnOpen_Click);
controls.Add(item);
}
lstItems.ItemsSource = controls;
Both events fire as expected. Previously, I had not had a "PreviewMouseLeftButtonUp" event, so left-clicking the button would only ever trigger the "Click" event. However, with that event added, left-clicking the button triggers both -- first the "PreviewMouseLeftButtonUp" from the listview, and then the "Click" from the UserControl.
I'm looking for a way to ignore the "Preview" event when the button is clicked, triggering only the "Click" event instead. Is there a way to make these disparate events play nice together? Or do I need to find another place to put the "PreviewMouseLeftButtonUp" code?