Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The <code>UniformGrid</code> is a layout control. You cannot interact directly with it.</p> <p>To achieve what you need, I propose you this solution.</p> <ol> <li>Create a <code>ItemsControl</code> element</li> <li>Change the <code>ItemsPanel</code> to a <code>UniformGrid</code></li> <li>Use the <a href="http://punker76.github.io/gong-wpf-dragdrop/" rel="nofollow">GongSolutions.Wpf.DragDrop project</a>. You can install it from nuGet <a href="http://www.nuget.org/packages/gong-wpf-dragdrop/" rel="nofollow">http://www.nuget.org/packages/gong-wpf-dragdrop/</a></li> </ol> <p>This solution can be written without any code-behind or VM code.</p> <pre><code>&lt;Window x:Class="WpfApplication6.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:system="clr-namespace:System;assembly=mscorlib" xmlns:dd="clr-namespace:GongSolutions.Wpf.DragDrop;assembly=GongSolutions.Wpf.DragDrop" Title="MainWindow" Height="350" Width="525"&gt; &lt;ItemsControl Height="150" dd:DragDrop.IsDragSource="True" dd:DragDrop.IsDropTarget="True"&gt; &lt;ItemsControl.ItemsPanel&gt; &lt;ItemsPanelTemplate&gt; &lt;UniformGrid Rows="1" /&gt; &lt;/ItemsPanelTemplate&gt; &lt;/ItemsControl.ItemsPanel&gt; &lt;ItemsControl.Items&gt; &lt;system:String&gt;Item 1&lt;/system:String&gt; &lt;system:String&gt;Item 2&lt;/system:String&gt; &lt;system:String&gt;Item 3&lt;/system:String&gt; &lt;/ItemsControl.Items&gt; &lt;/ItemsControl&gt; &lt;/Window&gt; </code></pre> <p><strong>Update:</strong></p> <p>If you need to drag items from another control then add this to your code-behind file.</p> <pre><code>public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); DataContext = this; SourceOfItems = new List&lt;string&gt;() { "Source 1", "Source 2", "Source 3" }; Items = new ObservableCollection&lt;string&gt;() { "Item 1", "Item 2", "Item 3" }; } public ObservableCollection&lt;string&gt; Items { get; private set; } public List&lt;string&gt; SourceOfItems { get; private set; } } </code></pre> <p>And update your XAML like this:</p> <pre><code>&lt;Window x:Class="WpfApplication6.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:dd="clr-namespace:GongSolutions.Wpf.DragDrop;assembly=GongSolutions.Wpf.DragDrop" Title="MainWindow" Height="350" Width="525"&gt; &lt;StackPanel&gt; &lt;ListBox ItemsSource="{Binding SourceOfItems}" dd:DragDrop.IsDragSource="True" dd:DragDrop.IsDropTarget="False"/&gt; &lt;ItemsControl Height="150" dd:DragDrop.IsDragSource="True" dd:DragDrop.IsDropTarget="True" ItemsSource="{Binding Items}" Background="Plum" &gt; &lt;ItemsControl.ItemsPanel&gt; &lt;ItemsPanelTemplate&gt; &lt;UniformGrid Rows="1" /&gt; &lt;/ItemsPanelTemplate&gt; &lt;/ItemsControl.ItemsPanel&gt; &lt;/ItemsControl&gt; &lt;/StackPanel&gt; &lt;/Window&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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