Sunday 15 August 2010

wpf - How can i be notified of a right click event of a Listbox in C# -


I am trying to determine if a user has right clicked on the existing listback entry or empty part, enabled Or the context menus to disable.

In WinForms (for a datagrid view) I was able to do this

  var result = DGV Task. Hit Test (EX, EY); Selected Boole Exists Selected = Results Type == DataGridViewHitTestType.Cell; In a datagrid view,  

I have now tried in WPF

  point pt = e.GetPosition ((UIElement) LBXWorkflow); HitTestResult Results = VisualTreeHelper.HitTest (LBXWorkflow, PT);  

The Result.VisualHit text box shows, if I click on existing text, but limit if I click on an empty space before or after the text on an existing line (which I use it wrong to determine if any entry was right clicked).

Any ideas, both listboxes and datagrid?

PLS check the code given below; This is a mouse button buttontone event handler that prints the item name under mouse pointer for box control if it is a private zeros-box box. 1_MouseRightButtonUp (Object Sender, MouseButtonEventArgs e) {Object Item = GetElementFromPoint (listBox1, e .GetPosition (ListBox1)); If (item! = Null) console; light line (item); Else Console Type ("no items found"); } Private Object GetElementFromPoint (ItemsControl ItemsControl, Point Point) {// You can use VisualTreeHelper.HitTest or itemsControl.InputHitTest method; Among them, the UII element element = VisualTriehaller as both the UIILEMENT. Hit Test (items control, point) will work. UIElement element = itemsControl.InputHitTest (point) as UIElement; While (element! = Null) {if (element == item control) tap back; Object item = itemscontrol ITEM Container Generator. ITomfort Container (element); If (! Item Ecloss (Dependency Property. Uet Valley)) return item; Element = (UIElement) VisualTreeHelper.GetParent (element); } Return tap; }

This list should work fine for the box


No comments:

Post a Comment