tag:blogger.com,1999:blog-3761674922653685009.post3640358982947773791..comments2014-12-17T15:58:37.404-08:00Comments on unfold: Silverlight Toolkit Drag Drop (Part 2): Customizing Drag and Drop BehaviorJafar Husainhttp://www.blogger.com/profile/15444397760399385108noreply@blogger.comBlogger44125tag:blogger.com,1999:blog-3761674922653685009.post-41850791529510693552010-09-03T23:12:12.030-07:002010-09-03T23:12:12.030-07:00Jafar, I wrapped the Drag Drop API you created in ...Jafar, I wrapped the Drag Drop API you created in the Silverlight Toolkit into DragDrop using attached properties. I got the idea from Pavan Podila&#39;s work in WPF that really helped me earlier. Here is the link: http://sl4dragdrop.codeplex.com/ . Hopefully it will be of some help to other people.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-3761674922653685009.post-83507230112995386512010-07-15T13:30:31.302-07:002010-07-15T13:30:31.302-07:00Hi Jafar,
I have a ListBox and a Treeview.I can d...Hi Jafar,<br /><br />I have a ListBox and a Treeview.I can drag items from ListBox and drop on to Treeview. I don&#39;t want to drop item above or below the treeview node. I tried to do in the drop event of TreeViewDragDropTarget but of no use. I am not able to cancel the drop event. How can I achieve this? Please help me.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-3761674922653685009.post-19913897769570115862010-07-13T03:27:59.260-07:002010-07-13T03:27:59.260-07:00For copying from a listbox to a treeview, I use an...For copying from a listbox to a treeview, I use an ItemDragStarting on the source ListBoxDragDropTarget..<br /><br /> private void ListBoxDragDropTarget_ItemDragStarting(object sender, ItemDragEventArgs e)<br /> {<br /> ((SelectionCollection)e.Data)[0] = new System.Collections.ObjectModel.Selection(((InteractiveNode)((SelectionCollection)e.Data)[0].Item).Clone()); <br /> }<br /><br />Only implemented for single item, (InteractiveNode is my dragged object)<br /><br />Steve RonaldStephenhttp://www.blogger.com/profile/18141986880822359459noreply@blogger.comtag:blogger.com,1999:blog-3761674922653685009.post-28994532783238977522010-05-07T10:29:18.043-07:002010-05-07T10:29:18.043-07:00Shivaji:
If you want to limit tree view item move...Shivaji:<br /><br />If you want to limit tree view item moves to within the current level of hierarchy then you have to hook the DragOver,DragEnter,DragLeave, and Drop events and set the Effects property of the DragEventArgs to None when the target location is outside of the current hierarchy. <br /><br />I suggest you subclass TVDDT. This will give you access to the protected GetDropTarget which accepts a DragEventArgs. This method will allow you to find out the intended drop target of a drag operation.<br /><br />Scott B:<br /><br />The Blend exception is almost certainly due to the fact that DDT inherits from ContentControl and when Blend inserts a CC onto a design surface it adds some content to it. This wouldn&#39;t be a problem but the DDT&#39;s throw an exception unless their Content is set to the correct type. A ListBoxDDT throws if its content is not set to a ListBox, etc.<br /><br />The solution is to create a DefaultInitializer for your custom DDT. By doing so you can prevent Blend from adding Content to the DDT at design-time. See my former manager Ning Zhang&#39;s blog for details. http://www.ningzhang.org/2009/05/11/editing-model-default-initializer-for-silverlight-controls/<br /><br />michael_p_lockwood:<br /><br />In order to drag and drop from a data source it must implement various interfaces (INCC and IList). I suspect that the DomainDataSource dosn&#39;t implement one of these.<br /><br />Avinash:<br /><br />In order to hide the drag image you can hook the ItemDragStarting event and set the DragDecoratorContent property on the ItemDragEventArgs to null. If you want to change the style of the drag decorators there is a template part called &quot;InsertionIndicator&quot; of type path.Jafar Husainhttp://www.blogger.com/profile/15444397760399385108noreply@blogger.comtag:blogger.com,1999:blog-3761674922653685009.post-79138723365374645522010-05-07T00:42:44.956-07:002010-05-07T00:42:44.956-07:00hi Jafar,
I want to know how to
retemplate the L...hi Jafar,<br />I want to know how to <br /> retemplate the ListBoxDragDropTarget control, and how change the color of insertion indicator and hide the drag snapshot .please help meAvinashhttp://www.blogger.com/profile/00013326919788745872noreply@blogger.comtag:blogger.com,1999:blog-3761674922653685009.post-7242093455347758932010-04-23T02:30:57.486-07:002010-04-23T02:30:57.486-07:00Hi Jafar!
How do you drag a data grid header cont...Hi Jafar!<br /><br />How do you drag a data grid header content and copy/drop it to an itemscontrol?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-3761674922653685009.post-71179627239156985382010-04-21T16:18:05.992-07:002010-04-21T16:18:05.992-07:00Jafar,
I have used the DragDropTargets with a s...Jafar, <br /><br />I have used the DragDropTargets with a standard dataGrid, but now i am attempting this with the datagrid&#39;s itemsource being bound to a RIA DomainDataSource. For some reason this does not allow for drag or drop, have you seen this?michael_p_lockwoodhttp://www.blogger.com/profile/08298900514151184959noreply@blogger.comtag:blogger.com,1999:blog-3761674922653685009.post-58067052304914329432010-04-02T11:20:11.146-07:002010-04-02T11:20:11.146-07:00I&#39;m having problems inheriting a DDT. I simpl...I&#39;m having problems inheriting a DDT. I simply created a class that inherits from the TreeViewDragDropTarget. I can create a UserControl, put the new DDT inside of it with a TreeView inside of the new DDT. So far so good... The problem is that I can not place that UserControl on any page or other UserControl without Blend giving me the big red box error: <br />ArgumentNullException: Value cannot be null.<br />Parameter name: stream<br /><br />However, the code compiles and runs.<br /><br />I have no idea why I can&#39;t do a simple inheritance. Any ideas? I must be missing something.<br /><br />Thanks for your help.Scott Bnoreply@blogger.comtag:blogger.com,1999:blog-3761674922653685009.post-56400291226091460082010-04-01T03:10:34.593-07:002010-04-01T03:10:34.593-07:00How do I customize it to allow the drag and drop o...How do I customize it to allow the drag and drop only between the elements at same heirarchy level in a tree view. Currently I see that the elements are draggable across heirarchies. Basically what I need is, interchanging the elements&#39; position which are in the same heirarchy level in a treeview.Shivajihttp://www.blogger.com/profile/00571490203093273603noreply@blogger.comtag:blogger.com,1999:blog-3761674922653685009.post-1939060101546706422010-03-14T00:52:36.482-08:002010-03-14T00:52:36.482-08:00Sergey Prokhorenko: This embarrassing bug has bee...Sergey Prokhorenko: This embarrassing bug has been fixed in the new version of the Toolkit which should be released very soon.<br /><br />B: Please do log those bugs in CodePlex and include all of that information. Thanks very much.<br /><br />Anonymous: AttachEvent is a wrong. It should be AddHandler. Sorry for the confusion.Jafar Husainhttp://www.blogger.com/profile/15444397760399385108noreply@blogger.comtag:blogger.com,1999:blog-3761674922653685009.post-46997295228170025072010-03-10T02:29:19.379-08:002010-03-10T02:29:19.379-08:00Hi I need to drag / drop data grid item into stack...Hi I need to drag / drop data grid item into stack panel.<br /><br />Cant figure it out. <br /><br />I also cant find AttachEvent anywhere (tried object browser in VS, text search in Toolkit Nov 09 source / samples)... <br /><br />Where in Silverlight is AttachEvent ???<br /><br /><br />Thank youAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-3761674922653685009.post-155179075960211322010-03-09T01:55:54.663-08:002010-03-09T01:55:54.663-08:00Hi Jafar,
1) I noticed that when we are dragging t...Hi Jafar,<br />1) I noticed that when we are dragging the mouse faster then the dropping is not happening. This is happening in the SLToolkit sample as well. The item being dragged gets removed from source list, however it does not appear in the destination list box.<br />2) Another problem is related to positioning of the tranparent background (decorator). When you start drag for the first time just notice that it appears at 0,0 and not at the mouse location. Once you drop it, then subsequent drag-drop operation starts the background image at the last drop position. Dragging slowly hides the problem somewhat, however it is more prominent when you drag faster.<br /><br />The reason for this seems to be the below code in DragDropTarget.cs:<br /><br /> <i> private void OnItemDragStarted(ItemDragEventArgs args)<br /> {<br /> _currentItemDragEventArgs = args;<br /> _itemWasDroppedOnSource = false;<br /><br /> GeneralTransform transform = Application.Current.RootVisual.SafeTransformToVisual(_dragPopup);<br /> Point offset = new Point(0, 0);<br /> if (transform != null)<br /> {<br /> offset = transform.Transform(new Point(0, 0));<br /> }<br /><br /> _dragPopup.HorizontalOffset = offset.X;<br /> _dragPopup.VerticalOffset = offset.Y;<br /> ...<br /> }</i><br /><br />as the actual location is being decided in:<br /> <i>private void OnDragging(MouseEventArgs args)<br /> {<br /> Point mouseLocation = args.GetSafePosition(Application.Current.RootVisual);<br /> if (double.IsNaN(mouseLocation.X))<br /> {<br /> mouseLocation = new Point(0, 0);<br /> }<br /> Canvas.SetLeft(_dragDecorator, mouseLocation.X - _currentItemDragEventArgs.DragDecoratorContentMouseOffset.X);<br /> Canvas.SetTop(_dragDecorator, mouseLocation.Y - _currentItemDragEventArgs.DragDecoratorContentMouseOffset.Y);<br /> }</i><br /><br />And I think, when dragging mouse faster OnDragging is not getting called.<br /><br />Should I log a bug for both of these issues?Bhttp://www.blogger.com/profile/18180850436214818652noreply@blogger.comtag:blogger.com,1999:blog-3761674922653685009.post-88490572393433369642010-03-05T03:09:05.910-08:002010-03-05T03:09:05.910-08:00Hi. I use DataGridDragDropTarget which works fine,...Hi. I use DataGridDragDropTarget which works fine, but whatever row I drag, it always shows the first source grid&#39;s row as the transparent dragged image. Is it a bug? Also, how can I setup my own dragged image? Is it via DragDecoratorContent in ItemDragStarting?<br /><br />Another question, how can I detect the target row in the target grid when dropped? Currently I do this using mouse position and hit testing, because I haven&#39;t found any &quot;target row&quot; data in events.Sergey Prokhorenkohttp://www.blogger.com/profile/06389461574659526392noreply@blogger.comtag:blogger.com,1999:blog-3761674922653685009.post-21322924742507335142010-02-19T19:12:57.567-08:002010-02-19T19:12:57.567-08:00Hey Jenna,
Sure you can hide it. Just retemplate...Hey Jenna,<br /><br />Sure you can hide it. Just retemplate the control. You&#39;ll see the insertion indicator path in there. Just remove it or set it&#39;s opacity to 0.Jafar Husainhttp://www.blogger.com/profile/15444397760399385108noreply@blogger.comtag:blogger.com,1999:blog-3761674922653685009.post-53179850399481639142010-02-19T09:00:01.141-08:002010-02-19T09:00:01.141-08:00Hi Jafar,
Ok, nevermind about my previous request...Hi Jafar,<br /><br />Ok, nevermind about my previous requests. What I ended up doing was removing the ItemSource bindings and created a few targetedtriggeractions to work around the problem. Basically, the drag and drop works now properly although I could not bind the ItemSource..(I am manually populating the listbox since there will always only be one item). <br /><br />I do have just one more question... I noticed that if you are trying to drag and drop into a listbox that there is this insertion line that appears on DragEnter... In my case, I don&#39;t want to show it... Is it possible to remove the insertion line or hide it ?<br /><br />Thank you,<br />Jenna212firehttp://www.blogger.com/profile/16942133311771856109noreply@blogger.comtag:blogger.com,1999:blog-3761674922653685009.post-87888021061373674662010-02-11T14:52:46.959-08:002010-02-11T14:52:46.959-08:00212fire: Are you sure you&#39;re bound to an OC. ...212fire: Are you sure you&#39;re bound to an OC. This might happen if you were bound to a ReadOnlyCollection or an array, or you are overriding the default action to copy.<br /><br />Are you holding down control when you drag? That switches the default action to copy.Jafar Husainhttp://www.blogger.com/profile/15444397760399385108noreply@blogger.comtag:blogger.com,1999:blog-3761674922653685009.post-70887668720384890292010-02-10T13:14:36.669-08:002010-02-10T13:14:36.669-08:00Hi Jafar,
I have a question... I am trying to use ...Hi Jafar,<br />I have a question... I am trying to use drag and drop in my application that allows users to &quot;drop occupants into seats of a vehicle.&quot; <br />So, I have created a ListBoxDragDropTarget/ListBox with each seat having their own LBDDT/ListBox all within the vehicle&#39;s listbox data template. Then I also have a LBDDT/ListBox for the occupants the user can drag from and into the Vehicle Seat...<br />All of these listboxes are bound to their own ObservableCollections. The problem is that when I try to drag a person from one listbox into the Vehicle seat - it uses the DragDrop &quot;Copy&quot; effect rather than using the &quot;Move&quot; effect which is what I need... Please let me know what you think or how I can fix this...<br /><br />Thanks Jafar!212firehttp://www.blogger.com/profile/16942133311771856109noreply@blogger.comtag:blogger.com,1999:blog-3761674922653685009.post-10157409931958963452010-02-01T22:54:26.140-08:002010-02-01T22:54:26.140-08:00Hi Jafar,
I&#39;ve logged the bug here:
http://si...Hi Jafar,<br /><br />I&#39;ve logged the bug here:<br />http://silverlight.codeplex.com/WorkItem/View.aspx?WorkItemId=5213<br /><br />You can see the problem here:<br />http://www.screencast.com/users/NovelBase/folders/Jing/media/a11eecb8-f8df-4cb9-b884-a772b0a2f6a5<br /><br />Maybe I&#39;m not understanding how the treeview &amp; dragdrop should deal with adjusting hierarchical data correctly?Colinnoreply@blogger.comtag:blogger.com,1999:blog-3761674922653685009.post-29525608896976111742010-01-31T09:17:37.919-08:002010-01-31T09:17:37.919-08:00Colin: Hmmm. Not really. I&#39;d consider addin...Colin: Hmmm. Not really. I&#39;d consider adding an option for the next release but it&#39;s not really a common scenario. If you disagree log a request on CodePlex and other people can vote on it. <br /><br />That said it&#39;s probably a good idea to instead get to the bottom of the data duplication bug. If you think it&#39;s a TVDDT issue please create a contained repro and log it on CodePlex.Jafar Husainhttp://www.blogger.com/profile/15444397760399385108noreply@blogger.comtag:blogger.com,1999:blog-3761674922653685009.post-55597741465985663172010-01-29T21:35:00.285-08:002010-01-29T21:35:00.285-08:00Hi Jafar,
Is there a way to disable dragging abov...Hi Jafar,<br /><br />Is there a way to disable dragging above/below nodes in the TreeViewDragDropTarget?<br />I can&#39;t find the exact problem, but it seems to be duplicating items (overwriting existing data!) so I need to find a way to disable it, while still enabling dragging into a node.<br />I can&#39;t find much info about the DragDropTargets on the web about this except for your blog!Colinnoreply@blogger.comtag:blogger.com,1999:blog-3761674922653685009.post-34963653359338343372010-01-21T08:02:40.157-08:002010-01-21T08:02:40.157-08:00The Select method is an extension method. Just im...The Select method is an extension method. Just import &quot;System.Linq&quot; and it will be added to the SelectionCollection object for you.Jafar Husainhttp://www.blogger.com/profile/15444397760399385108noreply@blogger.comtag:blogger.com,1999:blog-3761674922653685009.post-72218265660022735012010-01-21T02:21:56.314-08:002010-01-21T02:21:56.314-08:00Could please tell me why the method select in sele...Could please tell me why the method select in selectionCollection.Select statement the method doesn&#39;t exist. I am using the System.Collections.ObjectModel namespace for the SelectionCollection object.Martinhttp://www.blogger.com/profile/04531129733143947909noreply@blogger.comtag:blogger.com,1999:blog-3761674922653685009.post-17342016576838559822010-01-20T08:13:52.781-08:002010-01-20T08:13:52.781-08:00Good catch Bupesh,
I&#39;ll apply this workaround...Good catch Bupesh,<br /><br />I&#39;ll apply this workaround in the next Toolkit release.Jafar Husainhttp://www.blogger.com/profile/15444397760399385108noreply@blogger.comtag:blogger.com,1999:blog-3761674922653685009.post-5921902089484614122010-01-20T04:59:29.768-08:002010-01-20T04:59:29.768-08:00Got the exact issue. Toolkit is using RenderSize p...Got the exact issue. Toolkit is using RenderSize property to determine the original source for the drag operation (refer - Controls.Toolkit\DragDrop\DragOperation.cs, function - GetDragOverOriginalSource)<br /><br /> node =&gt; new Rect(new Point(0, 0), node.<b>RenderSize</b>).Contains(args.GetPosition(node)))<br /><br />In my case the RenderSize for Image element is (0,0) and hence the original source changes to its parent. This is a bug in Silverlight refer the link: http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=520507<br /><br />The workaround that I can think of is to use ActualWidth/ActualHeight properties as below:<br /> node =&gt; new Rect(new Point(0, 0), new Size( (node as FrameworkElement).<b>ActualWidth</b>, (node as FrameworkElement).<b>ActualHeight</b>)).Contains(args.GetPosition(node)))<br /><br />What other approach do you suggest?Bhupeshnoreply@blogger.comtag:blogger.com,1999:blog-3761674922653685009.post-55192146380768720332010-01-18T21:56:54.302-08:002010-01-18T21:56:54.302-08:00I am trying to drag an image from a list to anothe...I am trying to drag an image from a list to another element inside a canvas, however I am not getting the OnDrop event. Here is the sample XAML for drop target:<br /><br />&lt;UserControl x:Class=&quot;DragDropSample.DropControl&quot;<br /> xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;<br /> xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;<br /> xmlns:d=&quot;http://schemas.microsoft.com/expression/blend/2008&quot;<br /> xmlns:mc=&quot;http://schemas.openxmlformats.org/markup-compatibility/2006&quot;<br /> mc:Ignorable=&quot;d&quot;<br /> d:DesignHeight=&quot;300&quot; d:DesignWidth=&quot;200&quot;&gt;<br /> &lt;Canvas x:Name=&quot;ParentCanvas&quot; Width=&quot;200&quot; Height=&quot;300&quot; Background=&quot;AliceBlue&quot; AllowDrop=&quot;false&quot;&gt;<br /> &lt;Canvas x:Name=&quot;childCanvas&quot; Canvas.Left=&quot;50&quot; Canvas.Top=&quot;70&quot; Width=&quot;80&quot; Height=&quot;150&quot; Background=&quot;Aqua&quot; AllowDrop=&quot;true&quot;/&gt;<br /> &lt;Image x:Name=&quot;childImage&quot; Source=&quot;Images/BlueLoveCirclesWallpaper.jpg&quot; Width=&quot;200&quot; Height=&quot;100&quot; AllowDrop=&quot;true&quot;/&gt;<br /> &lt;/Canvas&gt;<br />&lt;/UserControl&gt;<br /><br />The user control’s class is inherited from IAcceptDrop.<br />Here are my observations (Note – I have referred elements with their x:Name attribute):<br />1) I am getting DragEnter event however immediately I get DragLeave event for both “childCanvas” and “childImage” which is wrong as mouse is still inside the canvas/image. As a result of this I am not getting the OnDrop event<br />2) If I remove the ParentCanvas and host the Image element directly inside the User control then everything works fine.<br />3) If I change AllowDrop for ParentCanvas to true I get the OnDrop event however the OriginalSource is the ParentCanvas and not the child element on which the drop happened.<br />My guess is this is a bug, any suggestions?<br />I want to replace the image with the drag source image.Bhupeshnoreply@blogger.com