Intersoft ClientUI Documentation
SetData Method



Set data object.
Overload List
OverloadDescription
SetData(Object) Set data object.  
SetData(String,Object) Set data object.  
SetData(Type,Object) Set data object.  
SetData(String,Object,Boolean) Set data object.  
Remarks

When dealing with drag and drop, it is common to assign a data to be carried during the drag and drop operation. The drag-drop framework in ClientUI also provides this architecture to store the data in multiple formats.

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);
    }
}
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

DragDropEventData Class
DragDropEventData Members

Concepts

Drag-drop Framework Overview

Send Feedback