1

ツリービューにある xmldata をキャンバスにドラッグ ドロップしたいのですが、取得できません。いくつかのコードを試してみましたが、何か不足している可能性があります。以下は私のコードです。

//handler for mouse move event
private void treeview_mousemove(object sender,MouseEventArgs e) 
{
    if (e.LeftButton == MouseButtonState.Pressed) 
    {
        DataObject data = new DataObject();
        data.SetData(DataFormats.StringFormat, treeView1.SelectedItem.ToString());
        data.SetData("string", treeView1.SelectedItem);
        data.SetData("Object", this);
        DragDrop.DoDragDrop(this,data, DragDropEffects.Copy);
    }
}

//handler for drop event attached in canvas (Don`t know what to do here)  getting 
InvalidOperationException {Logical tree depth exceeded while traversing the tree. This could indicate a cycle in the tree.}
private void treeview_drop(object sender,DragEventArgs e)
{
    e.Effects = DragDropEffects.None;
    UIElement uieve = (UIElement)e.Data.GetData("Object");
    if (e.Data.GetDataPresent(DataFormats.StringFormat))
    {
        canvas1.Children.Add(uieve);
        e.Effects = DragDropEffects.Copy;
    }
}

//handler for drag enter event in canvas
private void treeview_dragenter(object sender, DragEventArgs e)
{
    e.Effects = DragDropEffects.Copy;
}

//handler for dragover event
private void treview_dragover(object sender,DragEventArgs e)
{
    e.Effects = DragDropEffects.None;
    if (e.Data.GetDataPresent(DataFormats.StringFormat))
    {
        string data = (string)e.Data.GetData(DataFormats.StringFormat);
        e.Effects = DragDropEffects.Copy;
    }
}

キャンバスに xml 要素をドロップしたいだけですが、何をすべきかわかりません。前もって感謝します..

4

1 に答える 1

0

I think you can replace the canvas by a listview of your items, define ItemTemplate and DataTemplate. I use it actually in my project. it's more simple for drag n drop functions.

<ListView>
    <ListView.ItemsPanel>
        <ItemsPanelTemplate>
            <Canvas />
        </ItemsPanelTemplate>
    </ListView.ItemsPanel>
    <ListView.ItemTemplate>
        <DataTemplate>
             <!-- Your item representation -->
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

Michael,

于 2013-01-30T08:19:48.500 に答える