Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I build a WPF application where I can drag and drop a user control between windows?
    text
    copied!<p>I'm building a simple Todo List application where I want to be able to have multiple lists floating around my desktop that I can label and manage tasks in.</p> <p>The relevant UIElements in my app are:</p> <p>Window1 (Window) TodoList (User Control) TodoStackCard (User Control)</p> <p>Window1 looks like this:</p> <pre><code>&lt;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" &gt; &lt;Canvas Name="maincanvas" Width="500" Height="500" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"&gt; &lt;ResizeGrip SizeChanged="ResizeGrip_SizeChanged" /&gt; &lt;t:TodoList Canvas.Top="0" Canvas.Left="0" MinWidth="30" Width="50" Height="500" x:Name="todoList" TaskHover="todoList_TaskHover" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/&gt; &lt;/Canvas&gt; &lt;/Window&gt; </code></pre> <p>TodoList looks like this:</p> <pre><code>&lt;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"&gt; &lt;StackPanel VerticalAlignment="Bottom" HorizontalAlignment="Stretch" MinWidth="1" Grid.Row="2" Height="Auto" AllowDrop="True"&gt; &lt;ItemsControl Name="todolist" ItemsSource="{Binding}"&gt; &lt;ItemsControl.ItemsPanel&gt; &lt;ItemsPanelTemplate&gt; &lt;VirtualizingStackPanel Name="stackPanel" VerticalAlignment="Bottom"&gt; &lt;/VirtualizingStackPanel&gt; &lt;/ItemsPanelTemplate&gt; &lt;/ItemsControl.ItemsPanel&gt; &lt;ItemsControl.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;t:TodoStackCard x:Name="card" TaskHover="card_TaskHover" Orientation="Vertical" VerticalContentAlignment="Top" /&gt; &lt;/DataTemplate&gt; &lt;/ItemsControl.ItemTemplate&gt; &lt;/ItemsControl&gt; &lt;/StackPanel&gt; &lt;/UserControl&gt; </code></pre> <p>I have multiple instances of these windows, and I want to be able to drag any of the controls between the windows. I have tried using a Thumb control and, while this works, it only allows me to drag a control around the containing canvas. </p> <p>How do I mimic the behaviour of, say, Windows Explorer, where I can drag a file outside of the application and onto another application, all the while seeing a ghosted representation of the file under the cursor. </p> <p>Can I accomplish this purely in C# and WPF? If so/if not, how?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload