Intersoft ClientUI 8 > ClientUI Fundamentals > Drag-drop Framework Overview > Drag-drop Framework How-to Topics > How-to: Store Data Object at Drag Init Event |
The following examples show how to store a DataObject during drag-drop process.
DragSourceEvent (EventType = DragInit) and DragInitEvent are the events that raised when the drag is about to start, so it is the ideal event to store a DataObject if necessary.
This example shows how to store a DataObject that will be carried by the drag object.
Using Event Handler
XAML |
Copy Code
|
---|---|
<Grid x:Name="LayoutRoot"> <Intersoft:UXListBox x:Name="UXListBox1" HorizontalAlignment="Center" Height="200" VerticalAlignment="Center" Width="150" AllowMoveItem="True" AllowReorderItem="True" DragInit="UXListBox1_DragInit"> <Intersoft:UXListBoxItem Content="Freezed"/> <Intersoft:UXListBoxItem Content="Dragable Item 1"/> <Intersoft:UXListBoxItem Content="Dragable Item 2"/> </Intersoft:UXListBox> </Grid> |
C# |
Copy Code
|
---|---|
private void UXListBox1_DragInit(object sender, Intersoft.Client.UI.Controls.Interactivity.DragEventArgs e) { string sourceData = "Some string data to store..."; byte[] unicodeText = Encoding.Unicode.GetBytes(sourceData); byte[] utf8Text = Encoding.UTF8.GetBytes(sourceData); string uniCodeFormat = "Unicode"; string utf8DataFormat = "UTF-8"; DragDropEventData dataObject = e.Data as DragDropEventData; dataObject.SetData(sourceData); dataObject.SetData(uniCodeFormat, unicodeText); dataObject.SetData(utf8DataFormat, utf8Text); } |
Using DragInitEvent
XAML |
Copy Code
|
---|---|
<Grid x:Name="LayoutRoot"> <Intersoft:UXListBox x:Name="UXListBox1" HorizontalAlignment="Center" Height="200" VerticalAlignment="Center" Width="150" AllowMoveItem="True" AllowReorderItem="True"> <Intersoft:UXListBoxItem Content="Freezed"/> <Intersoft:UXListBoxItem Content="Dragable Item 1"/> <Intersoft:UXListBoxItem Content="Dragable Item 2"/> </Intersoft:UXListBox> </Grid> |
C# |
Copy Code
|
---|---|
public MainPage() { // Required to initialize variables InitializeComponent(); ISEventManager.RegisterInstanceHandler( this.UXListBox1, // any element in the routed path which applicable in your scenario ISDragDrop.DragInitEvent, // the routed event new Intersoft.Client.UI.Controls.Interactivity.DragEventHandler(UXListBox1_DragInit), // the event handler true); } private void UXListBox1_DragInit(object sender, Intersoft.Client.UI.Controls.Interactivity.DragEventArgs e) { string sourceData = "Some string data to store..."; byte[] unicodeText = Encoding.Unicode.GetBytes(sourceData); byte[] utf8Text = Encoding.UTF8.GetBytes(sourceData); string uniCodeFormat = "Unicode"; string utf8DataFormat = "UTF-8"; DragDropEventData dataObject = e.Data as DragDropEventData; dataObject.SetData(sourceData); dataObject.SetData(uniCodeFormat, unicodeText); dataObject.SetData(utf8DataFormat, utf8Text); } |
Using DragSourceEvent [DragInit]
XAML |
Copy Code
|
---|---|
<Grid x:Name="LayoutRoot"> <Intersoft:UXListBox x:Name="UXListBox1" HorizontalAlignment="Center" Height="200" VerticalAlignment="Center" Width="150" AllowMoveItem="True" AllowReorderItem="True"> <Intersoft:UXListBoxItem Content="Freezed"/> <Intersoft:UXListBoxItem Content="Dragable Item 1"/> <Intersoft:UXListBoxItem Content="Dragable Item 2"/> </Intersoft:UXListBox> </Grid> |
C# |
Copy Code
|
---|---|
public MainPage() { // Required to initialize variables InitializeComponent(); ISEventManager.RegisterInstanceHandler( this.UXListBox1, // any element in the routed path which applicable in your scenario ISDragDrop.DragSourceEvent, // the routed event new Intersoft.Client.UI.Controls.Interactivity.DragEventHandler(UXListBox1_DragInit), // the event handler true); } private void UXListBox1_DragInit(object sender, Intersoft.Client.UI.Controls.Interactivity.DragEventArgs e) { if (e.GetEventType() == DragEventType.DragInit) { string sourceData = "Some string data to store..."; byte[] unicodeText = Encoding.Unicode.GetBytes(sourceData); byte[] utf8Text = Encoding.UTF8.GetBytes(sourceData); string uniCodeFormat = "Unicode"; string utf8DataFormat = "UTF-8"; DragDropEventData dataObject = e.Data as DragDropEventData; dataObject.SetData(sourceData); dataObject.SetData(uniCodeFormat, unicodeText); dataObject.SetData(utf8DataFormat, utf8Text); } } |