WPF Drag and Drop - PullRequest
       1

WPF Drag and Drop

1 голос
/ 31 мая 2011

Как реализовать перетаскивание для приложения WPF? Я мог бы открыть 2 одинаковых приложения и перетащить объект из одного в другое. Вот что я хочу перетащить:

<Grid Width="100" Height="50">
 <Rectangle BackGround="Red"/>
 <TextBlock>Hello World</TextBlock>
</Grid>

Сетка должна выглядеть так же, как и в другом приложении, куда она перетаскивается, как та, которую перетаскивали. Любые решения?

Ответы [ 3 ]

1 голос
/ 02 мая 2012

При использовании поведения:

вам понадобится разметка, подобная этой:

<Window xmlns:i=
"clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
xmlns:custom=
"clr-namespace:CustomBehaviorsLibrary;assembly=CustomBehaviorsLibrary >

пример:

<Canvas>
<Rectangle Canvas.Left="10" Canvas.Top="10" Fill="Yellow" Width="40" Height="60">
</Rectangle>
<Ellipse Canvas.Left="10" Canvas.Top="70" Fill="Blue" Width="80" Height="60">
<i:Interaction.Behaviors>
<custom:DragInCanvasBehavior></custom:DragInCanvasBehavior>
</i:Interaction.Behaviors>
</Ellipse>
<Ellipse Canvas.Left="80" Canvas.Top="70" Fill="OrangeRed" Width="40" Height="70">
<i:Interaction.Behaviors>
<custom:DragInCanvasBehavior></custom:DragInCanvasBehavior>
</i:Interaction.Behaviors>
</Ellipse>

1 голос
/ 01 июня 2011

В прошлом я успешно использовал Gong Solutions Drag and Drop, это очень простая в использовании DLL. Вы можете увидеть небольшой образец этого здесь: Gong Solutions

0 голосов
/ 01 мая 2012

пример WPF Drag and Drop: использование vb.net 2010

        <Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Class="mofakfree"
        Title="drop test " Height="359" Width="329">
        <Grid>
                <Label x:Name="label2" AllowDrop="True"  Margin="159,30,12,0" Background="#FF1900FF" Content="To Here" DragEnter="label2_DragEnter" Drop="label2_Drop" Height="51" VerticalAlignment="Top" />
                <Label x:Name="label1" AllowDrop="True"  Margin="26,30,158,240" Background="#FFDE2626" Content="source" MouseDown="label1_MouseDown"/>
        </Grid>
        </Window>

код vb.net:

 Class mofakfree



        Private Sub label1_MouseDown(ByVal sender as Object, ByVal e as System.Windows.Input.MouseButtonEventArgs)
            'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
            Dim lbl As Label = CType(sender, Label)
            DragDrop.DoDragDrop(lbl, lbl.Content, DragDropEffects.Copy)
        End Sub

        Private Sub label2_DragEnter(ByVal sender as Object, ByVal e as System.Windows.DragEventArgs)
            'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
            If e.Data.GetDataPresent(DataFormats.Text) Then
        e.Effects = DragDropEffects.Copy
            Else
            e.Effects = DragDropEffects.None
        End If

        End Sub

        Private Sub label2_Drop(ByVal sender as Object, ByVal e as System.Windows.DragEventArgs)
            'xxxxxxxxxxxxxxxxxx
            CType(sender, Label).Content = e.Data.GetData(DataFormats.Text)

        End Sub

    End Class
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...