I have been searching the internet high and low but can't find some examples that can help me.
I'm developing an application in wpf, in it I use a DataGrid; each cell has a DataTemplate with and image, in a mosaic style; on the side of the grid I have some tiles to use on the grid.
I'm able to drag the tiles but can't drop them on the grid because I can't find the cell to which make the drop. Is there a way to get a cell position from the the drag events?
Thanks
I am assuming you suscribed to the drop event on the DataGrid.
Since you have a DataTemplate for each cell, you could subscribe to the drop event from the cell and you should be able to do the modification you want via e.Source.
If you need to you could define a different DataTemplate for each column so that you can figure at the column and then modifiy the data via
BusinessObject row = ((UIElementResponsibleForTeDrop)e.Source).DataContext;
Related
That might be a silly question, but I just can figure how to resolve it for now.
I'm building a wpf application with drag and drop between a ListView and a Grid.
My items being consituted by an Image and a TextBlock. I have defined a DataTemplate with a StackPanel containing these controls and applied it to ListView items and ContentControls inside of the Grid cells.
Basic idea is to chose items from the ListView and drag them to a cell. So my grid is empty at the beginning.
My problem, besides of sucking at making my controls filling correctly my grid (bonus ninja question !), is that when no item is chosen in a cell the image is not drawn and will not act as drop target. Only the TextBlock will.
Is there a way to counter that ? Thank you :)
You can set a datatemplate trigger so that you display an empty image that will accept the drop, if the contents are null.
And if that idea doesn't work, you can create a datatemplateselector that returns a template with a blank dropping target if the content is null. This shows how to make a selector that can let you set all possible templates using only xaml.
I have requirement where i have drag and drop row from datagrid to another datagrid using WPF application.
Can any one help with a sample code or any links to go through.
You may try the below tutorials for these... There are more examples over the internet.
http://msdn.microsoft.com/en-us/library/ms996459.aspx
DragAndDrop selectedItems of one silverlight Datagrid into another
http://www.dotnetcurry.com/ShowArticle.aspx?ID=677
http://www.blog.ingenuitynow.net/Silverlight+4+Drag+And+Drop+DataGrids+With+Access+To+The+Data+Being+Dropped.aspx
http://social.msdn.microsoft.com/Forums/en/wpf/thread/36c1160f-c63b-41ca-91f9-a38c934ee83b
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.
In my gridview I need to aggregate subrows into each row, something like in p2p emule/amule application where you can do double click to each file you are downloading and then under it you can see the parts of the file from where you are downloading.
Is it possible in WPF?
Thanks.
You could do a few things:
Add some container (ie: another Grid or a StackPanel) to the Grid row. This would let you add multiple objects to the grid row. On your "double click" event, you could change the visibility to show those objects.
Use a TreeView with a HierarchicalDataTemplate, and treat this as hierarchical data. This is most likely the more "correct" approach. The Displaying Hierarchical Data sample on MSDN walks through the process of this.
For example, dragging a row from a datagrid table to another datagrid table?
However the other datagrid table just present the row, it manipulates the data gathered and present it in its own way.
I am using wpf toolkit. Can show me a sample example on this?
Here is a good place to start. Although the tutorial is shown for ListBox, it can also be adapted for DataGrid (although I have not tried it for myself).