WPF GRID to GRID drag and drop - wpf

I am trying to find a way to drag and drop between two grids(NOT datagrids). Both grids have 3 columns and the second grid gets populated based on whats dropped from first grid and the rows on second grid are generated dynamically. First grid has custom controls as icons. I am unable to get the items on the first grid as row/column co-ordinates but the mouse event handler gives me the (x,y) point co-ordinatels. Is there an easy way of doing this?
Thanks.

If I understand correctly then the main problem you have is to get the control under your mouse cursor. You can get it by using either UIElement.InputHitTest or VisualTreeHelper.HitTest to get that control / visual. Also do check out this article on MSDN: Hit Testing in the Visual Layer - it is a well-written explanation of this process with examples.

Related

Row dragging in DataGrid

I have a DataGrid in a WPF application, right now when I click on a cell it highlights the whole row and when I then drag down the rows it highlights all of the rows in between.
What I need is for dragging over a row to copy the value from the cell you start on over all the rows you drag it over and only highlight the rows in the specific column.
The exact words in the request were "like Excel".
Is there a written control for this? I have searched SO and have not found exactly what I am looking for. If the control does not exist, what is a good starting place?
A good starting place for you to learn how to code Drag and Drop.
I recently created a treeview with Drag and Drop functionality.
You might get some ideas on how drag and drop works from this project.
You can download it here: https://drive.google.com/file/d/0B5WyqSALui0bYmJ4SkEzXzdmUk0/view?usp=sharing
If you need any help then feel free to ask....
Best of Luck.....

WPF - Displaying thumbnails in a grid as they arrive from an external source

I recently wrote a routine that displayed a grid of images from files in a folder. I used a vertically-oriented ListBox where each row in the ListBox was a horizontally-oriented StackPanel of the images. I just had to walk the folder tree and populate the StackPanel. It was simple, quick and easy to implement.
Now I have a new requirement. I'll be receiving the images one-at-a-time from a piece of factory equipment that will be sending one every few seconds and I need to display it as I get it. I still need to display these in a grid but the images start from the lower left and proceed to the right until a row is filled up, then we start a new row directly above it. We WILL know at the start the final dimensions, but it may be more than we can fit on a screen so scrolling will have to be enabled.
What are the right controls to use for this in WPF? Is there a way to reuse my ListBox/StackPanel scheme or are there more appropriate controls for this? Remember, the images must be displayed as I get them - I can't fill up a whole StackPanel and then do a
listBoxImages.Items.Add(myStackPanel)
... or can I - can I add an empty StackPanel to a parent and then populate one image at a time afterwards? What's the right way to go about this?
Based on the fact the number of images is known at the start of the routine, I would create a view model with a collection of collections.
The first is an observable collection with elements for each row, inside the element is another collection for each column. This can be bound to an items control where the content template has a second items control with horizontal orientation.
Then, as your images arrive, you start to fill the last element first with your image references and work back up. That should create the desired effect. Not sure how that works with scrolling as you effectively want the last element to be in view first, so scrolled to the end.
Another option, using a single collection is to bind to an items control with a uniform grid panel template. This can be wired up with a DataTemplateSelector which when the data is null, displays an empty template, otherwise shows an image box. This will allow you to again add elements to your collection in any order and it mirror on the UI.
An example of the data template selector can be found here. Or search SO.

WPF - Adding ScatterViewItem.Content to a StackPanel as UIElement

I'm attempting to make a application where you can drag ScatterViewItems next to each other, and the items will dock together, so that you can move them around as a single item.
Right now I'm trying to create a StackPanel and add the content of the two ScatterViewItems being docked to it, but am not sure how to convert the SVI's content property to a UIElement in any meaningful way. Has anyone tried to do something similar, or have any ideas on how to get it to work?
Look at the ScatterPuzzle example in the Surface SDK. It shows precisely how to accomplish this scenario of snapping items together

WPF Adorner Overlay Problem

I am trying to achieve functionality similar to that of a Popup, without using a Popup, but instead adorning my ContentControl with a basic adorner. Basically, I want the ContentControl to have an "overlay" effect, whereby it is the topmost object, above all other elements - similiar to that of the Popup control.
Here is the problem that I am running into, and I am hoping that someone can point out where I am going wrong:
I have a stand grid with two row definitions. The first row contains a UI element - for example, a rectangle. The second row contains a custom control that I have developed to emulate the functionality of a "drawer" sliding out. Basically, when I click on button, I am going to animate a TranslateTransform to "slide" my ContentControl "up". This works fine - except that it gets cropped underneath the rectange in the first row of the grid. If I remove the row definitions in the grid, then when the desired behavior is achieved - the ContentControl is moved "up" and partially "on top" of the rectangle. The rectangle is merely a place holder for what I am trying to achieve. I basically want to have a drawer type control that can slide out and be on top of all other controls.
I am somewhat new to using the Adorner class, so, I am hoping that someone can please point out where I am going wrong.
Thanks.
Chris
Change the parent of the adorner to the full grid, and not just your control. If you put a control in a grid row, and set the adorner to adorn the control, it will usually be clipped to that row because the control is.

Silverlight datagrid in usercontrol does not support sorting

If i create a datagrid on a silverlight page and bind it to a domaindatasource / ria services then i automatically get features like sorting/resizing/reordering of columns.
When i copy the exact same code into a usercontrol then the column headers lose these features. Is there something obvious im missing here?
Edit: I noticed that when i remove the associated pager beneath my grid, sorting gets enabled. The only question is why..
Alright.. the problem was that the pager was positioned on top of the grid (even though it looks like its positioned below the grid, its boundaries actually stretch across the whole grid), hence stealing all mouse and keyboard input. To resolve this one could set the z index of the pager to 0 and the z index of the grid to 1 (or perhaps use a stackpanel?)

Resources