views:

70

answers:

1

I am building a little app for the Windows Phone 7 (Silverlight 3) which allows the user to add objects to the screen and drag them around. My class is defined as the following:

 public class Frame
    {
        public double Height{ get; set; }
        public double Width { get; set; }
        public Uri Image { get; set; }
        public string Details { get; set; }
        public SolidColorBrush BgColor { get; set; }
    }

My question is about my approach on how to implement this. I am fairly new to SilverLight (have experience in WPF) and am finding out the things in WPF that are missing in SL3 (commanding, for instance). As I see it I could:
a) use a ListBox with a Canvas in the ItemsPanelTemplate and bind it to a ObservableCollection<Frame>. In WPF would use commands in the DataTemplate for the events involved in the Drag/Drop. But there are no commands in SL3.
b) As the user adds a new object, I could create an instance of Frame and then wire the necessary events. How can I apply a DataTemplate in this case?

Which route should I take? How to overcome the challenges describe above? Any better suggestion?

Thanks

+2  A: 

Take a look at the GestureListerner/GestureReceiver in the Silverlight Toolkit.
The source comes with a sample which demonstrates dragging an object.

Alternatively, look at the MultiTouch Behaviour created by Laurent Bugnion which also enables dragging.

Matt Lacey
Matt, thanks for your answer. I believe I know how to do the actual dragging. My question regarding my approach. Should I take route "a" or "b". Or perhaps use a templated ListBox and attach the events using the VisualTreeHelper...?
Gustavo Cavalcanti
Laurent's solution is very interesting if you have the object to be dragged already in place in design-time. In my case users create these objects themselves. So how would I apply the behavior after they are added?
Gustavo Cavalcanti