How to create a WPF application where I can drag and drop a user control between windows?

I am creating a simple Todo List application where I want to have several lists floating around my desktop that I can identify and manage tasks.

Relevant UIElements in my application:

Window1 (window) TodoList (User Control) TodoStackCard (User Control)

Window1 is as follows:

<Window x:Class="TaskHole.App.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:t="clr-namespace:TaskHole.App.Controls"
    xmlns:tcc="clr-namespace:TaskHole.CustomControls"
    Title="Window1" Width="500" Height="500" Background="Transparent" WindowStyle="None" AllowsTransparency="True" >
    <Canvas Name="maincanvas" Width="500" Height="500" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
        <ResizeGrip SizeChanged="ResizeGrip_SizeChanged" />
        <t:TodoList Canvas.Top="0" Canvas.Left="0" MinWidth="30" Width="50" Height="500" x:Name="todoList" TaskHover="todoList_TaskHover" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
    </Canvas>
</Window>

TodoList is as follows:

<UserControl x:Class="TaskHole.App.Controls.TodoList"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:t="clr-namespace:TaskHole.App.Controls"
    xmlns:tcc="clr-namespace:TaskHole.CustomControls"
    Background="Transparent">
<StackPanel VerticalAlignment="Bottom" HorizontalAlignment="Stretch" MinWidth="1" Grid.Row="2" Height="Auto" AllowDrop="True">
<ItemsControl Name="todolist" ItemsSource="{Binding}">
                        <ItemsControl.ItemsPanel>
                            <ItemsPanelTemplate>
                                <VirtualizingStackPanel Name="stackPanel" VerticalAlignment="Bottom">

                                </VirtualizingStackPanel>
                            </ItemsPanelTemplate>
                        </ItemsControl.ItemsPanel>
                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <t:TodoStackCard x:Name="card" TaskHover="card_TaskHover" Orientation="Vertical" VerticalContentAlignment="Top" />
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>
</StackPanel>
</UserControl>

I have several instances of these windows, and I want to be able to drag and drop any of the controls between the windows. I tried using the Thumb control, and although it works, it allows me to drag the control around the containing canvas.

, , Windows, , .

# WPF? / , ?

+3
2

DoDragDrop Drag And Drop. Jaime Rodriguez

+2

, FYI, " " , Explorer, Drag and Drop, , . , , WPF - . -, Data (IDataObject) , WPF-, DoDragDrop (- - WPF), . , , , , , , . http://www.codeproject.com/KB/wtl/wtl4mfc10.aspx, , . WPF , , , , IDragSourceHelper.

+1

Source: https://habr.com/ru/post/1697775/


All Articles