Small drag drop prob (probably really simple) - c#

I'm dragging an item from a surfacelistbox over something else, let's say for example it's a normal wpf grid - how can I tell where (i.e. what column/row) the item has been dropped on?
Thanks a lot,
Dan

Put a Panel inside each cell of your Grid. The drop target will then be one of those panels

Related

Placing multiple panels in a single cell of TableLayoutPanel in C# Winforms

I'm in the process of developing a C# Winforms application. I have divided the form into table cells using a TableLayoutPanel. For a particular cell of the table layout, I want to insert multiple panels - one over another, so that I can switch between panels(for that cell only) using BringToFront().
I tried the same on a form which seemed to work. In the cell of table layout, I am only able to add one panel into it. When I try to add other panels in that cell, these get embedded into the first panel. This makes it difficult to switch between panels.
I also tried inserting all the required panels into an empty panel(placed in the cell). But then, I'm not able to figure out how to switch among it's child panels.
Note: The switching of the panels is to be triggered by a ComboBox selection in some other cell of the table.
If you want to switch between panels, thats will always go wrong, because the bottom panel will become the parent of the top one...
#Hans Passant give a solution in another topic and citing:
This can be worked around with View > (Other Windows) > Document Outline, drag the top panel back to the form. Still pretty painful, you typically have to edit the Location by hand and making any changes to the form in the designer later tends to slurp the panel back.
There are better ways to do this. Creating UserControls instead is highly recommended, they have their own design surface. Or use the RAD way and do this with a TabControl instead
Full Credits: Credits

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

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.

Custom Scrolling with ListView

I've been tasked at work with creating a UserControl containing a ListView and ComboBox's for sorting the ListView data. Sorting with the Combobox's s the easy part; the part with which I'm having difficulty is implementing a method of scrolling. In the end, the control should have an Excel-like feel to it. However, sometimes the ListView is too tall or wide for where it is placed. Therefore, there two be two scrollbars somewhere on the control. One vertically moves of the ListView only, and the other moves both the ListView and ComboBox filters horizontally.
Please note in the image above that the ComboBox's do adjust themselves according to column width, but the code for that is not enabled at the moment.
What I've tried: In the control, the filter boxes are in their own panel, and the ListView has had its own panel at times. I've tried using various combinations of the HScroll/VScroll and HorizontalScroll/VerticalScroll properties and the native function ShowScrollBar() for all the controls, but nothing has worked. The only way I've gotten scrollbars to appear is by settings AutoScroll (Scrollable for the ListView) to true. Of course, the scroll bars come in pairs and work only on the same control. I also attempted to programmatically move the scroll bars, but I haven't been able to accomplish that, either.
I've got to be doing something wrong, but I'm not sure what it is. Any help is appreciated!
I think I'd go for a different solution.
If you put the ComboBoxes in a AutoSrcoll panel with the same Anchors as the ListView you would give your users the freedom to scroll the two independently.
Yes, a ScrollBar would appear and take space but I would still happily sell that as a feature, not a bug ;-)
As for handling the Scroll event of a ListView: It is hidden and you'll have to subclass it to get access to it. See here

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

Space-filling ToolBar item in WPF

How can I make an item inside a ToolBar fill all the remaining available space? Or, how to right-align some items, since that would give me the same effect in my case.
Note that solutions which involve nesting another container (like a Grid) inside the ToolBar don't work since that disables the special behaviour ToolBar gives to it's items (like no normal borders and look, simple outline border on hover, not receiving focus after click, etc.).
Additionally, anyone knows how to get rid of the little button that would show additional icons that overflowed from the toolbar if I had any?
I ended up using this solution:
http://karlshifflett.wordpress.com/2008/01/23/wpf-sample-series-stretch-toolbar-width-of-window/
It's not ideal, but it works. I still don't know how to get rid of the dropdown on the end though.
You can remove the button at the end by re-templating the toolbar. You can likely solve your other query this way too.
I wrote up a soluton for creating a "space filling" label that dynamically sizes to allow to you "right-align" items in a toolbar. Check it out: WPF Toolbar Items HorizontalAligment="Right"

Categories