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 aListBox
with a Canvas in the ItemsPanelTemplate
and bind it to a ObservableCollection<Frame&g开发者_如何学编程t;
. 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
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.
精彩评论