protected override void OnMouseRightButtonDown(MouseButtonEventArgs e) { var mouseTarget = InputHitTest(Mouse.GetPosition(this)) as DependencyObject; var targetListViewItem = UIHelpers.FindVisualAncestorByType <ListBoxItem>(mouseTarget); if (targetListViewItem != null) { e.Handled = true; return; } base.OnMouseRightButtonDown(e); }
protected override void OnContextMenuOpening(ContextMenuEventArgs e) { var mouseTarget = InputHitTest(Mouse.GetPosition(this)) as DependencyObject; var targetListViewItem = UIHelpers.FindVisualAncestorByType <ListBoxItem>(mouseTarget); if (targetListViewItem == null) { e.Handled = true; return; } var tradeRoute = targetListViewItem.DataContext as TradeRoute; if (tradeRoute == null) { e.Handled = true; return; } PopulateTradeRouteMenu(tradeRoute); base.OnContextMenuOpening(e); }