开发者

Drag and drop between two user controls

I have a user control which has a TreeView control in it as flowing...

<Grid>

    <!-- Tree View -->

    <TreeView Name="devices" 
              ItemsSource="{Binding Entities}" AllowDrop="True">              

        <TreeView.ItemContainerStyle>
            <Style TargetType="{x:Type TreeViewItem}">
                <EventSetter Event="PreviewMouseLeftButtonDown"  Handler="EventPreviewMouseLeftButtonDown"/>
                <EventSetter Event="Drop"  Handler="EventDrop"/>
                <EventSetter Event="DragOver"  Handler="EventDragOver"/>
                <Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
                <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
                <Setter Property="FontWeight" Value="Normal" />
                <Style.Triggers>
                    <Trigger Property="IsSelected" Value="True">
                        <Setter Property="FontWeight" Value="Bold" />
                     </Trigger>
                </Style.Triggers>

            </Style>
        </TreeView.ItemContainerStyle>

        <TreeView.I开发者_如何学JAVAtemTemplate>

            <HierarchicalDataTemplate ItemsSource="{Binding Children}"> 
                <StackPanel Orientation="Horizontal">
                    <Image  Width="25" Height="25" Source="{Binding ImagePath}" />
                    <Button Background="Transparent"  BorderBrush="Transparent">
                        <TextBlock Text="{Binding Name}"/>
                    </Button>
                    <StackPanel.ToolTip>
                        <TextBlock Text="{Binding  Description}"/>
                    </StackPanel.ToolTip>
                </StackPanel>

            </HierarchicalDataTemplate>

        </TreeView.ItemTemplate>

    </TreeView>
</Grid>

I am using this usercontrol from my main window as flowing....

<StackPanel Grid.Column="0" Grid.Row="0"    Orientation="Vertical" AllowDrop="False">

<local:DevicesTreeview x:Name="srcDevices"  Height="220"/>
<local:DevicesTreeview x:Name="destDevices"     Height="220"/>

</StackPanel>

I am trying to draging a leaf Node from 'srcDevices' and droping on a leaf Node of 'destDevices' using DragDrop.DoDragDrop. Draging is initiating but no dragdrop event is firing (i.e. DragEnter/DragLeave/DragOver/Drop). How I can fix this problem?

Saquia


You have AllowDrop="False" on your stack panel, i dont know if this will stop you dropping on items in that, but i would remove it and see if it makes a difference. Also your drop events are on the tree view item not the tree view, is this the behaviour you want? or do you want to drop on the tree view, in which case your event handlers should be there.

Drag and Drop Tutorial


Thanks for your reply.

I have solved my problem. First I tried to use flowing statements to initialige drag and drop...

DataObject dragData = new DataObject(); DragDrop.DoDragDrop(this.devices, dragData, DragDropEffects.Link);

But now I am using flowing statement and now all drag drop event is firing...

DragDrop.DoDragDrop(this.devices, treeViewItem, DragDropEffects.Move);

So only difference is the second parameter which I am sending is different.

Thanks again

Saquia

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜