Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>After a bit of work I think I have it:</p> <pre><code>&lt;StackPanel Orientation="Horizontal"&gt; &lt;Controls:ListBoxDragDropTarget AllowDrop="True"&gt; &lt;ListBox x:Name="FromBox" Width="200" ItemsSource="{Binding IssueList}" DisplayMemberPath="Name"/&gt; &lt;/Controls:ListBoxDragDropTarget&gt; &lt;Controls:ListBoxDragDropTarget AllowDrop="True" Drop="ToBoxDragDropTarget_Drop"&gt; &lt;ListBox x:Name="ToBox" Width="150" ItemsSource="{Binding ObjectiveList}" DisplayMemberPath="Name" Margin="80,0,0,0" /&gt; &lt;/Controls:ListBoxDragDropTarget&gt; &lt;TextBlock x:Name="UpdateText"/&gt; &lt;/StackPanel&gt; </code></pre> <p>and the codebehind (which will now be refactored into my ViewModel):</p> <pre><code>public partial class MainPage : UserControl { public MainPage() { InitializeComponent(); IssueList = new ObservableCollection&lt;Issue&gt; { new Issue{ ID = 1, Name="One"}, new Issue{ ID = 2, Name="Two"}, new Issue{ ID = 3, Name="Three"}, new Issue{ ID = 4, Name="Four"}, new Issue{ ID = 5, Name="Five"}, }; ObjectiveList = new ObservableCollection&lt;Objective&gt; { new Objective {ID = 10, Name = "Ten"}, new Objective {ID = 11, Name = "Eleven"}, new Objective {ID = 12, Name = "Twelve"}, new Objective {ID = 13, Name = "Thirteen"}, new Objective {ID = 14, Name = "Fourteen"}, }; LayoutRoot.DataContext = this; } public ObservableCollection&lt;Issue&gt; IssueList { get; set; } public ObservableCollection&lt;Objective&gt; ObjectiveList { get; set; } private void ToBoxDragDropTarget_Drop(object sender, Microsoft.Windows.DragEventArgs e) { var droppedOnObjective = ((FrameworkElement)e.OriginalSource).DataContext as Objective; var args = e.Data.GetData(typeof(ItemDragEventArgs)) as ItemDragEventArgs; if (args != null) { var draggedItems = args.Data as SelectionCollection; var draggedItem = draggedItems[0]; if (droppedOnObjective != null) { var draggedIssue = (Issue)draggedItem.Item; if (!droppedOnObjective.Issues.Contains(draggedIssue)) { droppedOnObjective.Issues.Add(draggedIssue); UpdateText.Text = string.Format("Issue &lt;{0}&gt; added to Objective &lt;{1}&gt;", draggedIssue.Name, droppedOnObjective.Name); } else { UpdateText.Text = string.Format("Objective &lt;{0}&gt; already contains Issue &lt;{1}&gt;", droppedOnObjective.Name, draggedIssue.Name); } } else UpdateText.Text = "selections or dropOnObjective is null"; } else UpdateText.Text = "args null"; } } public class Issue { public int ID { get; set; } public string Name { get; set; } } public class Objective { public int ID { get; set; } public string Name { get; set; } public List&lt;Issue&gt; Issues { get; set; } public Objective() { Issues = new List&lt;Issue&gt;(); } } </code></pre>
 

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