Set data object.
Overload List
Example
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);
}
}
|
Remarks
Requirements
Target Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, Windows Vista, Windows Server 2008 family
See Also