From 43eef0c3e2fa21f7297bba9c9f031366e6668fce Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 2 Apr 2020 23:03:26 +0200 Subject: [PATCH 1/5] prototype for drag drop --- .../DesignData/DesignDataCard.cs | 20 +++++++++++ .../DesignData/DesignDataListCards.cs | 10 ++++++ .../DesignData/ResourceDictionary.xaml | 34 ++++++++++++++++++- .../Message/DropMessage.cs | 16 +++++++++ .../UserControls/Card.xaml | 6 ++-- .../UserControls/Card.xaml.cs | 13 +++++++ .../UserControls/CardsWarpPanel.xaml | 19 ++++++----- .../UserControls/CardsWarpPanel.xaml.cs | 26 ++++++++++++++ .../ViewModels/MainViewModel.cs | 17 ++++++++++ .../Views/MainWindow.xaml | 3 +- Planungsboard.sln | 4 +-- 11 files changed, 154 insertions(+), 14 deletions(-) create mode 100644 Planungsboard.Presentation/DesignData/DesignDataCard.cs create mode 100644 Planungsboard.Presentation/DesignData/DesignDataListCards.cs create mode 100644 Planungsboard.Presentation/Message/DropMessage.cs diff --git a/Planungsboard.Presentation/DesignData/DesignDataCard.cs b/Planungsboard.Presentation/DesignData/DesignDataCard.cs new file mode 100644 index 0000000..89a1960 --- /dev/null +++ b/Planungsboard.Presentation/DesignData/DesignDataCard.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Planungsboard.Presentation.ViewModels; + +namespace Planungsboard.Presentation.DesignData +{ + public class DesignDataCard : Card + { + public DesignDataCard() + { + var rnd = new Random(); + var alpha = "qwertzuioplkjhgfdsayxcvbnm"; + this.Effort = rnd.Next(1, 10) ^ 2; + this.Id = rnd.Next(10000, 99999).ToString(); + this.Title = alpha.OrderBy(c => Guid.NewGuid()).Take(rnd.Next(3, 5)).Select(c => c.ToString()).Aggregate((s, s1) => s + s1).ToUpper(); + } + } +} diff --git a/Planungsboard.Presentation/DesignData/DesignDataListCards.cs b/Planungsboard.Presentation/DesignData/DesignDataListCards.cs new file mode 100644 index 0000000..fcb2802 --- /dev/null +++ b/Planungsboard.Presentation/DesignData/DesignDataListCards.cs @@ -0,0 +1,10 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Planungsboard.Presentation.DesignData +{ + public class DesignDataListCards : List + { + } +} diff --git a/Planungsboard.Presentation/DesignData/ResourceDictionary.xaml b/Planungsboard.Presentation/DesignData/ResourceDictionary.xaml index 46c8183..bc00f0b 100644 --- a/Planungsboard.Presentation/DesignData/ResourceDictionary.xaml +++ b/Planungsboard.Presentation/DesignData/ResourceDictionary.xaml @@ -1,7 +1,39 @@  + xmlns:viewModels="clr-namespace:Planungsboard.Presentation.ViewModels" + xmlns:userControls="clr-namespace:Planungsboard.Presentation.UserControls" + xmlns:designData="clr-namespace:Planungsboard.Presentation.DesignData"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Planungsboard.Presentation/Message/DropMessage.cs b/Planungsboard.Presentation/Message/DropMessage.cs new file mode 100644 index 0000000..e94bca1 --- /dev/null +++ b/Planungsboard.Presentation/Message/DropMessage.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Windows.Controls; +using Planungsboard.Presentation.ViewModels; + +namespace Planungsboard.Presentation.Message +{ + public class DropMessage + { + public Card Card { get; set; } + public ItemsControl DropTarget { get; set; } + public int DisplayQuarterIndex { get; set; } + public Team Team { get; set; } + } +} diff --git a/Planungsboard.Presentation/UserControls/Card.xaml b/Planungsboard.Presentation/UserControls/Card.xaml index 2a69a0c..4d88df3 100644 --- a/Planungsboard.Presentation/UserControls/Card.xaml +++ b/Planungsboard.Presentation/UserControls/Card.xaml @@ -2,11 +2,13 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" - xmlns:local="clr-namespace:Planungsboard.Presentation.UserControls" mc:Ignorable="d" + d:DesignWidth="200" - d:DesignWidth="200"> + MouseMove="Card_OnMouseMove" + > (ViewModels.Card) this.GetValue(ItemProperty); set => this.SetValue(ItemProperty, value); } + + private void Card_OnMouseMove(object sender, MouseEventArgs e) + { + base.OnMouseMove(e); + if (e.LeftButton == MouseButtonState.Pressed) + { + DataObject data = new DataObject(); + data.SetData("Object", this.Item); + + DragDrop.DoDragDrop(this, data, DragDropEffects.Copy | DragDropEffects.Move); + } + } } } \ No newline at end of file diff --git a/Planungsboard.Presentation/UserControls/CardsWarpPanel.xaml b/Planungsboard.Presentation/UserControls/CardsWarpPanel.xaml index 664108d..9e064f4 100644 --- a/Planungsboard.Presentation/UserControls/CardsWarpPanel.xaml +++ b/Planungsboard.Presentation/UserControls/CardsWarpPanel.xaml @@ -5,8 +5,8 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:Planungsboard.Presentation.UserControls" mc:Ignorable="d" - d:DataContext="{d:DesignInstance local:CardsWarpPanel}" - d:DesignHeight="450" d:DesignWidth="800"> + + d:DesignHeight="100" d:DesignWidth="800"> - + @@ -34,16 +36,17 @@ + ItemsSource="{Binding Quarter1Cards}" + Style="{StaticResource ItemsControlStyle}" + Drop="Quarter1Cards_OnDrop"/> diff --git a/Planungsboard.Presentation/UserControls/CardsWarpPanel.xaml.cs b/Planungsboard.Presentation/UserControls/CardsWarpPanel.xaml.cs index 97c580a..f0d12c4 100644 --- a/Planungsboard.Presentation/UserControls/CardsWarpPanel.xaml.cs +++ b/Planungsboard.Presentation/UserControls/CardsWarpPanel.xaml.cs @@ -1,6 +1,9 @@ using System.Collections.Generic; using System.Windows; using System.Windows.Controls; +using GalaSoft.MvvmLight.Messaging; +using Planungsboard.Presentation.Message; +using Planungsboard.Presentation.ViewModels; namespace Planungsboard.Presentation.UserControls { @@ -49,5 +52,28 @@ public List Quarter4Cards get => (List) this.GetValue(Quarter4CardsProperty); set => this.SetValue(Quarter4CardsProperty, value); } + + public static readonly DependencyProperty TeamProperty = DependencyProperty.Register( + "Team", typeof(Team), typeof(CardsWarpPanel), new PropertyMetadata(default(Team))); + + public Team Team + { + get { return (Team) GetValue(TeamProperty); } + set { SetValue(TeamProperty, value); } + } + + private void Quarter1Cards_OnDrop(object sender, DragEventArgs e) + { + var card = e.Data.GetData("Object") as ViewModels.Card; + var senderControl = sender as ItemsControl; + + Messenger.Default.Send(new DropMessage() + { + Card = card, + DropTarget = senderControl, + Team = this.Team, + DisplayQuarterIndex = 0, + }); + } } } \ No newline at end of file diff --git a/Planungsboard.Presentation/ViewModels/MainViewModel.cs b/Planungsboard.Presentation/ViewModels/MainViewModel.cs index 0320d07..4d02831 100644 --- a/Planungsboard.Presentation/ViewModels/MainViewModel.cs +++ b/Planungsboard.Presentation/ViewModels/MainViewModel.cs @@ -4,6 +4,7 @@ using System.Linq; using GalaSoft.MvvmLight; using GalaSoft.MvvmLight.CommandWpf; +using Planungsboard.Presentation.Message; using Planungsboard.Presentation.Views; namespace Planungsboard.Presentation.ViewModels @@ -69,6 +70,22 @@ public MainViewModel() } this.FutureCards = futureCards; + + MessengerInstance.Register(this,this.DropMessageHandling ); + } + + private void DropMessageHandling(DropMessage dropMessage) + { + if (dropMessage.Card.AssignedQuarter == null || !dropMessage.Card.AssignedQuarter.Any()) + { + dropMessage.Card.AssignedQuarter = new List {this.DisplayQuarters[dropMessage.DisplayQuarterIndex]}; + } + + dropMessage.Team.Cards.Add(dropMessage.Card); + + // TODO + this.Teams = new ObservableCollection(this.Teams); + base.RaisePropertyChanged(() => this.Teams); } public List FutureCards { get; set; } diff --git a/Planungsboard.Presentation/Views/MainWindow.xaml b/Planungsboard.Presentation/Views/MainWindow.xaml index 7792de7..a381ac8 100644 --- a/Planungsboard.Presentation/Views/MainWindow.xaml +++ b/Planungsboard.Presentation/Views/MainWindow.xaml @@ -116,7 +116,7 @@ - + @@ -186,6 +186,7 @@ + @@ -37,7 +38,7 @@ Date: Tue, 7 Apr 2020 17:50:35 +0200 Subject: [PATCH 5/5] Update MainViewModel.cs --- Planungsboard.Presentation/ViewModels/MainViewModel.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Planungsboard.Presentation/ViewModels/MainViewModel.cs b/Planungsboard.Presentation/ViewModels/MainViewModel.cs index 1c6b07f..b4b55ed 100644 --- a/Planungsboard.Presentation/ViewModels/MainViewModel.cs +++ b/Planungsboard.Presentation/ViewModels/MainViewModel.cs @@ -228,7 +228,6 @@ public double TeamLabelWidth public RelayCommand LoadedCommand { get; set; } public RelayCommand QuarterNextCommand { get; set; } public RelayCommand QuarterBackCommand { get; set; } - public RelayCommand NewTeamCommand { get; set; } #endregion