Disable cross-slide selection ListView - c#

I would like to disable the cross-slide selection behavior for items in my ListView. I am aware of the property IsSwipeEnabled="False" however I still want to allow the user to drag and drop items into another Grid. I also tried capturing the Manipulation started / completed events with the following code.
MyListView.ManipulationMode = ManipulationModes.TranslateRailsX;
MyListView.ManipulationStarted += OnManipulationStarted;
MyListView.ManipulationCompleted += OnManipulationCompleted;
The appropriate events are caught in both handlers however I do not know what actions I should do to disable the selection to occur. I tried a similar approach I did for disabling right-clicking where I set the RoutedEvents.Handled to true but this does not prevent the selection from happening. Is there a clean way to handle this event and disable the selection to happen?

I can think of two things to try
Handle SelectionChanged events and deselect whatever got selected while otherwise allowing drag & drop to work naturally.
Do the above + disable swipe selection and handle drag & drop manually - set MyListView.ManipulationMode = ManipulationModes.TranslateRailsX | ManipulationModes.System, handle manipulation events to initiate and handle drag & drop inputs, call CancelDirectManipulations() on the dragged item container when you decide to switch from pan/scroll to drag&drop interaction, render a dragged item indicator in an adorner layer (just a panel on top of the ListView with some element attached to your finger), then handle drop on the drop target element.

Related

How to disable mouse buttons in C# WPF?

During big files loading I want to disable mouse buttons to unable user to click on UI elements and triggers events.
Edit
When I am loading big size file in my WPF Caliburn Micro application I changed IsEnabled property of Listbox to false, because I want to disable a button during this process.
Next when file is loaded I changed IsEnabled property of Listbox to true.
After that every click on disabled button raised events and I did not want that.
I don't know how to remove this events, and where there are stored, so i thought that the easier way to solve this problem is to disable mouse buttons during file loading process. But it is also not easy...
Thank You in advance!
If you only want to disable mouse buttons, the user can still use the keyboard. So you need a different technique.
You can add a hidden Gird with Opacity="0.5" to your window. When you want to prevent the user from using the window, just call visible the grid.
What about overriding SelectionChanged event on ListBox and setting it to Handled = true when loading big data?

WPF Datagrid in ScrollView Captures Row Details ComboBox Scrolling events

I have a datagrid inside a scrollviewer. The rows of my datagrid can be expanded to show the details and edit the row items.
In order for the "page" to scroll when the number of rows/row details view pushes the grid too long, I am handling the PreviewMouseWheel event on the datagrid. This works until I have a combobox in my row details with a droplist that has enough items that it also needs to scroll.
When using the mouse wheel, the droplist will scroll, but so does the outer datagrid, effectively scrolling the contents "behind" the droplist and leaving the droplist in the wrong place.
My PreviewMouseWheel event handler does the following:
private void StampPartsDatagrid_PreviewMouseWheelForScrolling(object sender, MouseWheelEventArgs e)
{
StampingScrollViewer.ScrollToVerticalOffset(StampingScrollViewer.VerticalOffset - e.Delta / 3);
}
I tried to trap the dropdown/drop up event on the combo, and while that works, if I move the mouse outside the drop list and scroll with the wheel, the page doesn't scroll.
I looked through many articles on MSDN and SO but they were mostly about getting the datagrid to scroll when inside a scrollviewer.
Is there a way to do a hit test on the Preview scrolling event? Should I trap the mouse/enter leave on the droplist somehow? Should I be handling my scrolling differently?
Thanks
* EDIT *
I resolved this issue. I was overthinking the mouse wheel behaviour. By looking at the Windows settings panel page for regions, which has a very long combo list to display, I saw that if the combo list was dropped the mousewheel only applied to he dropped list. Moving the mouse outside the droplist and scrolling with the wheel has no effect.
Given this, I adopted the same behaviour by trapping the drop open /drop close events and controlling the outer scrolling. My new event handler, taken from this post (https://social.msdn.microsoft.com/Forums/vstudio/en-US/6fc503a6-ba53-4395-b9b8-f56301efd097/mousescroll-of-combobox-scrolls-the-page-as-well?forum=wpf) is this:
private void StampPartsDatagrid_PreviewMouseWheelForScrolling(object sender, MouseWheelEventArgs e)
{
if (!bDetailsComboDropped)
{
StampingScrollViewer.ScrollToVerticalOffset(StampingScrollViewer.VerticalOffset - e.Delta / 3);
}
}
If you don't like to have an bDetailsComboDropped field, you can also try to determine where the preview mouse wheel routed event is coming from. Specifically, check e.OriginalSource to get a reference to the WPF element that was actually triggering the event (or e.Source if you find it better for the purpose).
Combine this with a recursive function using VisualTreeHelper.GetParent to check whether any of the parent elements is a combo box part, or it ends with your root scroll viewer.
(Note: your solution with the Boolean flag might actually provide higher performance, I just posted this in case someone needs a source-oriented solution, e.g. if there were many other controls to check against scrolling internally, etc.)

What events are raised when a control is selected in the WPF design surface?

I'm trying to build a WPF control inheriting from Selector and I want to change the state of the control when one of its items are selected in the design surface. Despite hooking on a debugger, I can't seem to capture any useful events from the control. I've managed to capture it being initialised and the wrappers for its child elements being initialised around the items of the selection, but I can't see any change of state, or event being triggered when the control is selected.
Importantly, I want to detect when the item is selected either by the user selecting the control in the design view or in the markup.
I'm trying to achieve a behaviour like that of the TabControl, where selecting a tab brings it to the front and exposes any content associated with the tab. I can't fathom how it works at design-time though.
What do I need to do to detect that a control is selected?

Select / Unselect user control

I am creating an application in which i have a user control that can be added by user dynamically any number of times. Form also contains some other controls.
Suppose he has added the control 10 times.
Requirement:
1) When the control is selected, it should be highlighted and when the
other control is selected then the previous control looses the glow.
2) User can select multiple controls at the same time. Now all the
selected controls should be highlighted and the selection has to be
made with ctrl key.
There is also a possibility of moving the controls on the form.
What I have achieved:
1) I am able to add multiple controls dynamically.
2) I can change the location of one control dynamically.
3) I am able to highlight the control when it is clicked, but not able
to un-glow it when user has clicked elsewhere. Need to know which event of User control can be used for that. -- Got the solution for this. On mouse click i made the focus on the control and then handle GotFocus and Lost Focus events to golw and un-glow the control.
Problem Left:
No success in selecting multiple controls and dragging them
simultaneously. If i would be able to select multiple controls then
dragging would not be very difficult.
If you are talking about buttons, unfortunately you cant select multiple at a time..

Can I make this easier? Bubbling vs Tunneling in WPF?

I am working with drag and drop functionality in a WPF application.
I have a tree structure such as the following.
StackPanel
- Border 1
- Grid A
- Grid 1
- Grid 2
- Border 2
- Grid B
- Grid 1
- Grid 2
This is my attempt to show the tree representation of the UIElements in my WPF application.
so the stack panel contains Grids with nested grids within it. These are being defined dynamically in code, and not in XAML.
I have the inner Grids(1 & 2) handling Drag and Drop events. The problem I am having is that when a drop operation is being performed, and it is dropped on the border of one of the grids, it falls through and hits the StackPanel Drop. What I would like to do is when an item is dropped on the border, I would like it to fall through to the same drop event handler.
I am fairly new to the idea of Routed Events and Bubbling and Tunneling events. I am aware that I need this event to travel down the element hierarchy which makes me believe that I am in need for "Tunneling" Event. Does this mean that I am supposed to attach the border to an event handler. Right now I have the following code for the Grids to be subscribed to the event.
fieldItemGrid.PreviewDrop += Grid_Drop;
private void Grid_Drop(object sender,DragEventArgs e)
{
//React to Drop Event Here
}
Am I able to do something simpler then rewriting the code that goes here in a Border_Drop Event?
Thanks ahead of time.
I think it would be best to add a very tight (no padding) container (e.g., a Grid) around the area that should act as a dropzone. Then use the tight container to handle the drop.
this way it doesn't matter what borders are specified. Only a padding of the tight container or a margin on the child controls will then mess it up.
The way routing working the preview event starts at the top of the tree until it reaches the element that initiated the event and then the normal event starts at the element itself and works towards the top of the tree.
In your situation, if border is the drop target, the sequence goes this (if event goes unhandled):
PreviewDrop -> StackPanel
PreviewDrop -> Border
Drop -> Border
Drop -> StackPanel
so the event will never reach any of the inner grids when the drop occurs on an element outside the grids. In other words, it will never tunnel into any children of the drop target because the tunnel stops where the drop occurred. It makes sense, how would it know which child was the right child to tunnel into if there were more than one?
As a result, you have to install the drop event handler on the largest element that visually represents the conceptual drop target. You can either switch the order of "Border 1" and "Grid A" or move your drop event handler for "Grid A" to "Border 1".

Categories

Resources