-
- Andreas Schooll
- Posts: 25
- Joined:
Preventing a Listboxitem from getting selected
Hi,
i have a question related to ListBox / ListViews.
We are catching the MouseEvents in our lists ScrollViewers to do customized scrolling.
ScrollView.PreviewMouseDown += OnTouch;
ScrollView.PreviewMouseUp += OnTouchLost;
ScrollView.PreviewMouseMove += OnTouchMove;
Unfortunately if you scroll around the items in the lists will get selected. This happens on mousedown and in mousemove. We would like to select the items on MouseUp only if no scrolling has happened before. Is there a way to dispose the MouseEvents so the listItems will not receive them?
best regards,
Andreas
i have a question related to ListBox / ListViews.
We are catching the MouseEvents in our lists ScrollViewers to do customized scrolling.
ScrollView.PreviewMouseDown += OnTouch;
ScrollView.PreviewMouseUp += OnTouchLost;
ScrollView.PreviewMouseMove += OnTouchMove;
Unfortunately if you scroll around the items in the lists will get selected. This happens on mousedown and in mousemove. We would like to select the items on MouseUp only if no scrolling has happened before. Is there a way to dispose the MouseEvents so the listItems will not receive them?
best regards,
Andreas
-
-
sfernandez
Site Admin
- Posts: 3203
- Joined:
Re: Preventing a Listboxitem from getting selected
Hi,
ListBoxItems get selected responding to MouseLeftButtonDown and MouseRightButtonDown events. You should try handling these events by setting args.handled = true.
Other solution could be to handle Touch events so touches don't get promoted to Mouse events.
ListBoxItems get selected responding to MouseLeftButtonDown and MouseRightButtonDown events. You should try handling these events by setting args.handled = true.
Other solution could be to handle Touch events so touches don't get promoted to Mouse events.
-
- Andreas Schooll
- Posts: 25
- Joined:
Re: Preventing a Listboxitem from getting selected
Hi,
thanks for your response. I have tried to prevent the selection by setting the args.handled to true.
This works to prevent the selection on button down, but the items still get selected if i move the mouse (i.e. with left button still down) over another item. Is there a way to prevent this also?
More questions related to the first:
Is there a way to determine what item would have been selected in the MouseButtonDown events to select it later in the mouse button up event?
Can i add eventhandlers to the listviewitem to catch events directly inside the items?
Can i derive listviewitem class to customize it?
best regards,
Andreas
thanks for your response. I have tried to prevent the selection by setting the args.handled to true.
This works to prevent the selection on button down, but the items still get selected if i move the mouse (i.e. with left button still down) over another item. Is there a way to prevent this also?
More questions related to the first:
Is there a way to determine what item would have been selected in the MouseButtonDown events to select it later in the mouse button up event?
Can i add eventhandlers to the listviewitem to catch events directly inside the items?
Can i derive listviewitem class to customize it?
best regards,
Andreas
-
-
sfernandez
Site Admin
- Posts: 3203
- Joined:
Re: Preventing a Listboxitem from getting selected
The other event used by ListBoxItem to detect selection is MouseEnter, and that event is a Direct routed event, so you cannot cancel it before the control's own event handler is called.The items still get selected if i move the mouse (i.e. with left button still down) over another item. Is there a way to prevent this also?
You can use Hit Testing to determine which item would have been selected.Is there a way to determine what item would have been selected in the MouseButtonDown events to select it later in the mouse button up event?
Code: Select all
ListBoxItem FindItemUnderMouse(Visual rootElement, Point mousePosition)
{
HitTestResult hr = VisualTreeHelper.HitTest(rootElement, mousePosition);
Visual v = hr.visualHit;
while (v != null)
{
var item = v.As<ListBoxItem>();
if (item != null)
{
// item found
return item;
}
v = VisualTreeHelper.GetParent(v);
}
// item not found
return null
}
Yes, you will only need a reference to the ListBoxItem.Can i add eventhandlers to the listviewitem to catch events directly inside the items?
In C++ you have full support to inherit from any control and customize it. But in Unity control extension support is more limited (for example, you can't override event handlers).Can i derive listviewitem class to customize it?
Re: Preventing a Listboxitem from getting selected
May I ask you what kind of customized scrolling are you implementing? Is this for emulating touch events?We are catching the MouseEvents in our lists ScrollViewers to do customized scrolling.
-
- Andreas Schooll
- Posts: 25
- Joined:
Re: Preventing a Listboxitem from getting selected
Thanks for your respone. I will look into the details later and see if we can get something out of that.
Yes, it is to emulate touch events and to implement a touch scrolling with deceleration. We implemented this before the actual touch mechanism of scrollviewers got implemented. Currently we (and our customer) like the fact, that the scrolling behaviour works for the desktop and mobile version.
Yes, it is to emulate touch events and to implement a touch scrolling with deceleration. We implemented this before the actual touch mechanism of scrollviewers got implemented. Currently we (and our customer) like the fact, that the scrolling behaviour works for the desktop and mobile version.
Re: Preventing a Listboxitem from getting selected
Another alternative is that you enable the default touch behavior of the scrollviewer (intertia is also implemented) and redirect Mouse events to Touch events with the IRenderer.
In fact, we use this emulation here when we want to test Touch events in windows machines without Touch Screen. We should probably make this emulation available to everybody.
In fact, we use this emulation here when we want to test Touch events in windows machines without Touch Screen. We should probably make this emulation available to everybody.
Who is online
Users browsing this forum: Ahrefs [Bot], Google [Bot] and 9 guests