> > >
ItemsControl Drag Drop Behavior for WPF
Express yourself! Share your work with other members of the Expression Community.

Each contribution is licensed to you under a License Agreement by its owner, not Microsoft. Microsoft does not guarantee the contribution or purport to grant rights to it.

ItemsControl Drag Drop Behavior for WPF

Average Rating:  (8)
Description
Discussions (6)

  • Whether using DataTemplate will lost visualTree hierarchy?
    2 Posts | Last Post March 20, 2011
    • Hello Edwin,
      Thanks a lot for this great example. It is super useful for me. I am doing something similar but I have some extra requirement as well. Based on your listview, I have two listviews A and B on a canvas. And I have connection link(actually a wpf Path) between one item in A and another item in B.I need to dynamically update this link when I drag or drop the two items.
      I use this function to find the absolute location of item on my canvas:
      public void SetPosition()
          {
              Center = this.TransformToAncestor(FindAncestor<Canvas>(this)).Transform(new Point(this.ActualWidth / 2, this.ActualHeight / 2));
          }
      // "this" above is my item - it's a control class written by me and it's subclass of border
      
          // walk up the visual tree for parent of type T
          private static T FindAncestor<T>(DependencyObject current)
              where T : DependencyObject
          {
              do
              {
                  if (current is T)
                  {
                      return (T)current;
                  }
                  current = VisualTreeHelper.GetParent(current);
              }
              while (current != null);
              return null;
          }
      
      Now I am confused - why VisualTreeHelper.GetParent() return null as my item's ancestor? Why this item's parent is not my listview?
      Do you know whether I use DataTemplate will cause the visual tree hierarchy doesn't recognize listview as listviewItem's parent due to this listviewItem is actually in DataTemplate?
    • Actually I need to find the absolute location of the item on my canvas. Do you know whether there is a way I can avoid use the dataTemplate or I can get the absolute location without this FindAncestor Function? Thank you so much!
  • How to install?
    2 Posts | Last Post December 10, 2009
    • As a noob to Silverlight (and Windows development in general):
      
      How do I install this thingy into Expression Blend/ SketchFlow?
      
      I need it for a tutorial I am doing.
      
      Cheers, Bjørn
    • The download link is to a file with no .zip extension - add the extension and then you can expand it.
      This control was built for WPF so it cannot be used in Silverlight app.  You use it by adding it as a reference in your project (Add reference, browse to DLL).
      Bjørn - I too am looking for the DragDropItem behavior referenced in module 9 of the snowboard online videos for SketchFlow.  Apparently, this is a custom behavior they used in the MIX presentations and I can't find it anywhere!!!
      If you stop the video (09_BLN03SP1EN720_Working_with_Behaviors_in_SketchFlow) when he selects the behavior you can see that it is custom cause the flyout is different, says "Snowboard_Mix_Screens" and the DLL is Expression.Prototype.Screens.dll in his local c:\users\admin\sketchflow_starter_kit folder.  This is not included in the Assets of the Prototyping_with_Sketchflow_StarterKit download so until someone finds it and posts it somewhere, we're out of luck on that part of the tutorial.
  • Usage?
    1 Posts | Last Post October 31, 2009
    • Forgive me for asking a probably silly question, but what would this be used for?
      
      Is this something that other programmers would use when creating a program of their own or is it something a regular person could use to organise thier computer files?
      
      I ask as I am looking for a solution or work around to the fact that Auto Arrange can no longer be turned off in Windows 7.
  • Events
    2 Posts | Last Post October 08, 2009
    • Thanks for this control it works great.  One question though, I am using this in my MVVM application and was wondering how I can add additional events / commands?  For example I want to know when an item is being added or removed and what item it is.  It looks like I need the remove and add item notification in the helper class but can not figure out how to add them?  Thanks
    • Hi there, 
      
      sorry for late reply. I don't check this very often. Best way to know if an item is added or removed is to fire an event from the behavior itself. you can expose that event (with the object as an argument) in the behavior and you can subscribe to that in your parent xaml control and handle that. Hope that helps.
  • Jim Tomasko
    3 Posts | Last Post August 04, 2009
    • Excellent work Edwin.  Your inclusion of the DataTemplate property really makes this very complete.  I must admit that I have only been pouring over the code and the example for about an hour, so may come up with questions, but so far this appears to be a pretty complete solution.
    • Thanks! If you can think of ways to improve me, give me a shout. 
    • oops i meant improve it, not improve me :P
  • Victor Galaguza
    1 Posts | Last Post August 01, 2009
    • Edwin, your example helped me a lot. It really makes the Drag&Drop is very simple. Thanks.

Details

Rate it: