Make control transparent to drag events during drag-and-drop - c#

I have a ListView that acts as a drop target for drag and drop operations. When the list is empty, I place a TextBlock over top of it with a message informing users they can drag things there (both controls are contained in a single Grid cell to enable overlap). But... since the TextBlock is on top of the ListView, it intercepts the various events connected to drag and drop and prevents things from being dropped onto the message text itself.
I really don't want to add a drop handler to the TextBlock--is there any way I can simply make it "transparent" to drag and drop operations?
Something that just occurred to me while writing this which does work is to put the text below the list in the Z-order and then give the list a transparent background. But is this really the right way to achieve this? Ideally, there'd be a way to give the text one ZIndex for rendering, and a different one for hit testing.

Set IsHitTestVisible to False for TextBlock.

Related

XAML advice for implementing tab-bar

Is it possible to achieve the following visual effect in .NET MAUI/XAML:
The main concern is the outline (or lack thereof on the bottom) of the selected tab and the underline of the unselected tabs.
The goal is to be able to define an arbitrary number of Tabs for the application.
Is this possible with XAML alone?
Any help would be greatly appreciated
If I had to create custom controls I would go with the GraphicsView.
Create a custom control Tab with a canvas that draw it in function of it state, you can use StackLayout to stack them and TapGestureRecognizer to manage clicks events.
One of the main problem of a GraphicsView is that you can't attach click event to shapes you are drawing (one solution there) so you can't be really precise on the events if you don't want to manage bounding box yourself.
Or you can just use ImageButton for the tabs with a label in front for the text, it would be way easier but less flexible (tabs should all be the same sizes).

Dragdrop usercontrol to flowlayoutpanel in winforms

I'm building a drag/drop application in winforms c#, i need to drag a usercontrol and drop it to a flowlayoutpanle.
everything works fine, except the drop location, the flowpanel sets the droped items side by side.
how can I set the droped item to the the exact cursor position?
I'll extend my comment to an answer.
The problem is not based on drag'n'drop. The problem is based on a semantic level. A flowlayoutpanel is used, to automatically arrange it's contents.
See MSDN FlowLayoutPanel Control Overview
The FlowLayoutPanel control arranges its contents in a horizontal or
vertical flow direction. You can wrap the control's contents from one
row to the next, or from one column to the next. Alternately, you can
clip instead of wrap its contents.
So the flowlayoutpanel-control does exactly what it's supposed to do. If you want to give the dropped control a specific location based on coordinates you want to use a normal panel. A normal panel will not arrange its contents automatically.

Debugging drag and drop in wpf?

I have drag and drop working in my application.
However, I have been running into an issue which I am not able to figure out whats causing it...
Basically, I have two itemsControl's where I am enabling drag and drop between them.
When the user drags items, I create a drag adorner and then do a drop preview on the control.
In some cases, when the drag adorner moves from source to the next itemsControl (i.e the target itemsControl where the drop will happen)...The OnPreviewDragLeave() method on the drag source
is not being called!
So the drag adorner just gets stuck on top of the source itemsControl.
This happens only in some cases, the only thing I can think of is that some other element is setting e.Handled to true maybe?
But how can I effectively debug this in an easy way as these events get fired continuosly and setting breakpoints is not really an option...
Any suggestions are appreciated,
thanks

How to center selected grid row/column at the center of the window?

I just wasted my entire evening on something which I thought would be very simple but it seems WPF and Google are letting me down completely.
I need a grid, 6x6 of which I fill every row and column with a custom control. I want to be able to navigate through this grid via the keyboard (I can get those events, no problem) but I cannot seem to find how I can always have the selected grid row/column in the center of my window.
I found some carousel alike implementations, but most of them only work in a single direction and I want two way navigation, yet none seem to support this nor can I extend them to do this.
I essentially want to create a PSP alike grid navigation.
One easy way is to do this:
Create a scrollable form.
Add a 6x6 grid of child controls.
In the GotFocus (or similar) event for all the controls, set the parent form scroll offset to an appropriate position to centre the child.
This is pretty straight-forward thing to implement, with a little bit of maths to work out how to centre the x,y position of a control by setting the scroll offsets (it can be tricky/confusing, but as long as you understand the coordinate systems used for scrolling, not too bad)
Or, another approach that avoids scrolling via the windows APIs and using custom controls:
Create a form
Override OnPaint to draw your grid of 6x6 "controls" as simple graphical shapes or bitmap images centred on the selected "control".
Handle keyboard (KeyDown/Up) and mouse handling (MouseDown/Up) events to make the 36 areas of the graphic respond to user inputs in the way you desire. You'll have to track the selected item and force the window to redraw its graphics to show the new state. Enable double buffering to stop it flickering.
The first approach gives you a lot of windows-based handling for free (tabbing between controls, remembering where the input focus is, and directing events to separate classes for each "control", for example). The second approach strips away all this "help" but gives you complete control over everything, which can often help avoid unintended behaviours (e.g. it won't move the input focus when the user presses Tab unless you specifically write the code to make it do that).

In a WPF ListView how can I prevent auto scrolling?

I have a WPF ListView which currently scrolls everytime I click on an item which is only partially visible. How can I keep the control from scrolling that item into view (instead simply selecting the partially visible one)? This behavior is very annoying when doing a drag from this control.
Thanks.
Added: I am looking for a solution to keep the control itself from scrolling when contents are clicked that the control believes are not fully visible. Often this is by a few pixels and the scroll is not necessary.
The items scroll into view because the default behavior on list item click is to call BringIntoView(). You can add an event handler for the RequestBringIntoView event and catch it before it bubbles up from the ListViewItems to the ScrollViewer. In your handler, check the bounds of the sender against the visible region and if you decide that you don't need to scroll, set the event's Handled flag to true.
Since I'm currently on the road, I cannot try this, but have you tried playing around with CanContentScroll, and/or wrapping the scrollable content into a Panel, as suggested by the ScrollViewer Overview on MSDN?
In the worst case, you might want to replace the ListView's ItemsPanel by a hacked ScrollViewer with a "fuzz" factor, e.g. by capturing the RequestBringIntoView event.
have you tried this approach?
just as an addon, I don't know how much you know about the subject, but here is a good place to read more about it.
added:
I just found that you can prevent the mouse wheel of scrolling as well.

Categories