diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-06-10 19:30:27 +0300 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-06-10 19:30:27 +0300 |
| commit | 6323ea8d74be3440286acaf73cab98024a858499 (patch) | |
| tree | a07f3097f97459eb5f3ddf2c4f8650543b520e9d /Software/Visual_Studio | |
| parent | 6996aefc25a84e3942e757189575fd11665bbe84 (diff) | |
| download | Tango-6323ea8d74be3440286acaf73cab98024a858499.tar.gz Tango-6323ea8d74be3440286acaf73cab98024a858499.zip | |
Implemented Drag & Drop on LightTouchGrid.
Diffstat (limited to 'Software/Visual_Studio')
7 files changed, 124 insertions, 9 deletions
diff --git a/Software/Visual_Studio/Tango.DragAndDrop/DragThumb.cs b/Software/Visual_Studio/Tango.DragAndDrop/DragThumb.cs index 355ce9997..4ab56ccb1 100644 --- a/Software/Visual_Studio/Tango.DragAndDrop/DragThumb.cs +++ b/Software/Visual_Studio/Tango.DragAndDrop/DragThumb.cs @@ -13,7 +13,6 @@ namespace Tango.DragAndDrop { public DragThumb() { - Background = Brushes.Transparent; IsHitTestVisible = true; } diff --git a/Software/Visual_Studio/Tango.Touch/Controls/LightTouchDataGrid.cs b/Software/Visual_Studio/Tango.Touch/Controls/LightTouchDataGrid.cs index 074563bd5..54f7a66bb 100644 --- a/Software/Visual_Studio/Tango.Touch/Controls/LightTouchDataGrid.cs +++ b/Software/Visual_Studio/Tango.Touch/Controls/LightTouchDataGrid.cs @@ -16,6 +16,7 @@ using System.Windows.Media; using System.Windows.Media.Animation; using Tango.Core.Commands; using Tango.Core.EventArguments; +using Tango.DragAndDrop; using Tango.SharedUI.Helpers; using Tango.Touch.Components; @@ -33,6 +34,36 @@ namespace Tango.Touch.Controls private double touch_inertia_coefficiant = 10; private double bounce_offset_max = 100; + + public RelayCommand<DropEventArgs> OnDragAndDropCommand + { + get { return (RelayCommand<DropEventArgs>)GetValue(OnDragAndDropCommandProperty); } + set { SetValue(OnDragAndDropCommandProperty, value); } + } + public static readonly DependencyProperty OnDragAndDropCommandProperty = + DependencyProperty.Register("OnDragAndDropCommand", typeof(RelayCommand<DropEventArgs>), typeof(LightTouchDataGrid), new PropertyMetadata(null)); + + public DraggingSurface DraggingSurface + { + get { return (DraggingSurface)GetValue(DraggingSurfaceProperty); } + set { SetValue(DraggingSurfaceProperty, value); } + } + public static readonly DependencyProperty DraggingSurfaceProperty = + DependencyProperty.Register("DraggingSurface", typeof(DraggingSurface), typeof(LightTouchDataGrid), new PropertyMetadata(null)); + + + + public bool IsDraggable + { + get { return (bool)GetValue(IsDraggableProperty); } + set { SetValue(IsDraggableProperty, value); } + } + public static readonly DependencyProperty IsDraggableProperty = + DependencyProperty.Register("IsDraggable", typeof(bool), typeof(LightTouchDataGrid), new PropertyMetadata(true)); + + + + public double HeaderHeight { get { return (double)GetValue(HeaderHeightProperty); } @@ -122,6 +153,7 @@ namespace Tango.Touch.Controls base.OnApplyTemplate(); _items_control_rows = GetTemplateChild("PART_ItemsControl_Rows") as ItemsControl; _grid_rows = GetTemplateChild("PART_Grid_Rows") as Grid; + DraggingSurface = GetTemplateChild("PART_DraggingSurface") as DraggingSurface; _grid_rows.IsManipulationEnabled = true; _grid_rows.RegisterForMouseOrTouchDown(Handle_Mouse_Or_Touch_Down); @@ -264,14 +296,14 @@ namespace Tango.Touch.Controls column.SortDirection = column.SortDirection == ListSortDirection.Ascending ? ListSortDirection.Descending : ListSortDirection.Ascending; } - DrawRows(); + LayoutRows(); } protected virtual void OnItemsSourceChanged() { if (ItemsSource != null) { - DrawRows(); + LayoutRows(); if (ItemsSource is INotifyCollectionChanged) { @@ -283,10 +315,10 @@ namespace Tango.Touch.Controls private void LightTouchDataGrid_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { - DrawRows(); + LayoutRows(); } - private void DrawRows() + public void LayoutRows() { if (_items_control_rows == null) return; diff --git a/Software/Visual_Studio/Tango.Touch/Controls/LightTouchDataGrid.xaml b/Software/Visual_Studio/Tango.Touch/Controls/LightTouchDataGrid.xaml index 1c53e4cca..d931a04f6 100644 --- a/Software/Visual_Studio/Tango.Touch/Controls/LightTouchDataGrid.xaml +++ b/Software/Visual_Studio/Tango.Touch/Controls/LightTouchDataGrid.xaml @@ -3,6 +3,7 @@ xmlns:converters="clr-namespace:Tango.Touch.Converters" xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" xmlns:components="clr-namespace:Tango.Touch.Components" + xmlns:dragAndDrop="clr-namespace:Tango.DragAndDrop;assembly=Tango.DragAndDrop" xmlns:fa="http://schemas.fontawesome.io/icons/" xmlns:local="clr-namespace:Tango.Touch.Controls"> @@ -104,7 +105,12 @@ </ItemsControl.ItemContainerStyle> <ItemsControl.ItemTemplate> <DataTemplate> - <local:LightTouchDataGridRow Padding="0" Canvas.Top="{Binding RelativeSource={RelativeSource AncestorType=ContentPresenter},Path=(Canvas.Top),Mode=TwoWay}" Style="{Binding RelativeSource={RelativeSource AncestorType=local:LightTouchDataGrid},Path=RowStyle}"> + <local:LightTouchDataGridRow RenderTransformOrigin="0.5,0.5" + dragAndDrop:DragAndDropService.Draggable="{Binding RelativeSource={RelativeSource AncestorType=local:LightTouchDataGrid},Path=IsDraggable}" + dragAndDrop:DragAndDropService.Droppable="{Binding RelativeSource={RelativeSource AncestorType=local:LightTouchDataGrid},Path=IsDraggable}" + dragAndDrop:DragAndDropService.DraggingSurface="{Binding RelativeSource={RelativeSource AncestorType=local:LightTouchDataGrid},Path=DraggingSurface}" + dragAndDrop:DragAndDropService.MinDragOffset="2" + Padding="0" Canvas.Top="{Binding RelativeSource={RelativeSource AncestorType=ContentPresenter},Path=(Canvas.Top),Mode=TwoWay}" Style="{Binding RelativeSource={RelativeSource AncestorType=local:LightTouchDataGrid},Path=RowStyle}"> <components:Ripple RippleFactor="20" RippleBrush="Red" Disabled="{Binding RelativeSource={RelativeSource AncestorType=local:LightTouchDataGrid},Path=IsScrolling}" CornerRadius="{Binding RelativeSource={RelativeSource AncestorType=local:LightTouchDataGridRow},Path=CornerRadius}"> <ItemsControl ItemsSource="{Binding RelativeSource={RelativeSource AncestorType=local:LightTouchDataGrid},Path=Columns}"> <ItemsControl.ItemsPanel> @@ -144,6 +150,8 @@ </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> + + <dragAndDrop:DraggingSurface x:Name="PART_DraggingSurface" /> </Grid> </DockPanel> </Border> diff --git a/Software/Visual_Studio/Tango.Touch/Controls/LightTouchDataGridRow.cs b/Software/Visual_Studio/Tango.Touch/Controls/LightTouchDataGridRow.cs index c4e96ee48..2eee427bb 100644 --- a/Software/Visual_Studio/Tango.Touch/Controls/LightTouchDataGridRow.cs +++ b/Software/Visual_Studio/Tango.Touch/Controls/LightTouchDataGridRow.cs @@ -4,11 +4,35 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Controls; +using Tango.DragAndDrop; +using Tango.SharedUI.Helpers; namespace Tango.Touch.Controls { public class LightTouchDataGridRow : Border { + private bool _isLoaded; + private LightTouchDataGrid _grid; + public LightTouchDataGridRow() + { + this.Loaded += LightTouchDataGridRow_Loaded; + } + + private void LightTouchDataGridRow_Loaded(object sender, System.Windows.RoutedEventArgs e) + { + if (!_isLoaded) + { + _isLoaded = true; + _grid = UIHelper.FindAncestor<LightTouchDataGrid>(this); + DragAndDropService.AddDropHandler(this, OnDragAndDrop); + } + } + + private void OnDragAndDrop(object sender, DropEventArgs e) + { + _grid.OnDragAndDropCommand?.Execute(e); + _grid.LayoutRows(); + } } } diff --git a/Software/Visual_Studio/Utilities/Tango.UITests/MainWindow.xaml b/Software/Visual_Studio/Utilities/Tango.UITests/MainWindow.xaml index e80e81e9c..c90aabe5f 100644 --- a/Software/Visual_Studio/Utilities/Tango.UITests/MainWindow.xaml +++ b/Software/Visual_Studio/Utilities/Tango.UITests/MainWindow.xaml @@ -4,6 +4,8 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:Tango.UITests" + xmlns:dragAndDrop="clr-namespace:Tango.DragAndDrop;assembly=Tango.DragAndDrop" + xmlns:components="clr-namespace:Tango.Touch.Components;assembly=Tango.Touch" xmlns:controls="clr-namespace:Tango.SharedUI.Controls;assembly=Tango.SharedUI" xmlns:keyboard="clr-namespace:Tango.Touch.Keyboard;assembly=Tango.Touch" xmlns:touch="clr-namespace:Tango.Touch.Controls;assembly=Tango.Touch" @@ -11,7 +13,7 @@ Title="MainWindow" Height="500" Width="400" DataContext="{Binding RelativeSource={RelativeSource Self}}"> <Grid> - <touch:LightTouchDataGrid ItemsSource="{Binding Persons}" Margin="50" BorderThickness="1" BorderBrush="Black"> + <touch:LightTouchDataGrid ItemsSource="{Binding Persons}" Margin="50" BorderThickness="1" BorderBrush="Black" OnDragAndDropCommand="{Binding DropCommand}"> <touch:LightTouchDataGrid.CellStyle> <Style TargetType="touch:LightTouchDataGridCell"> <Setter Property="Padding" Value="10"></Setter> @@ -73,6 +75,21 @@ </DataTemplate> </touch:LightTouchDataGridColumn.CellTemplate> </touch:LightTouchDataGridColumn> + + <touch:LightTouchDataGridColumn SortMember="Index"> + <touch:LightTouchDataGridColumn.HeaderTemplate> + <DataTemplate> + <TextBlock Text="DRAG" Foreground="Orange"></TextBlock> + </DataTemplate> + </touch:LightTouchDataGridColumn.HeaderTemplate> + <touch:LightTouchDataGridColumn.CellTemplate> + <DataTemplate> + <dragAndDrop:DragThumb Background="Orange" Width="50" Height="50" components:Ripple.PreventRipple="True"> + <TextBlock IsHitTestVisible="False" Text="{Binding Index}"></TextBlock> + </dragAndDrop:DragThumb> + </DataTemplate> + </touch:LightTouchDataGridColumn.CellTemplate> + </touch:LightTouchDataGridColumn> </touch:LightTouchDataGrid.Columns> </touch:LightTouchDataGrid> </Grid> diff --git a/Software/Visual_Studio/Utilities/Tango.UITests/MainWindow.xaml.cs b/Software/Visual_Studio/Utilities/Tango.UITests/MainWindow.xaml.cs index a41ee5867..8dc2a96fa 100644 --- a/Software/Visual_Studio/Utilities/Tango.UITests/MainWindow.xaml.cs +++ b/Software/Visual_Studio/Utilities/Tango.UITests/MainWindow.xaml.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -13,13 +14,24 @@ using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; +using Tango.Core; +using Tango.Core.Commands; +using Tango.DragAndDrop; namespace Tango.UITests { - public class Person + public class Person : ExtendedObject { public String FirstName { get; set; } public String LastName { get; set; } + private int _index; + + public int Index + { + get { return _index; } + set { _index = value; RaisePropertyChangedAuto(); } + } + public int Age { get; set; } } @@ -39,7 +51,7 @@ namespace Tango.UITests DependencyProperty.Register("Persons", typeof(ObservableCollection<Person>), typeof(MainWindow), new PropertyMetadata(null)); - + public RelayCommand<DropEventArgs> DropCommand { get; set; } public MainWindow() { @@ -52,12 +64,27 @@ namespace Tango.UITests Age = i, FirstName = "Roy " + i.ToString(), LastName = "Ben Shabat " + i.ToString(), + Index = i, }); } + DropCommand = new RelayCommand<DropEventArgs>(OnDrop); + InitializeComponent(); } + private void OnDrop(DropEventArgs e) + { + var dragPerson = (e.Draggable as FrameworkElement).DataContext as Person; + var dropPerson = (e.Droppable as FrameworkElement).DataContext as Person; + + Debug.WriteLine(dragPerson.FirstName + " dropped on " + dropPerson.FirstName); + + int dragIndex = dragPerson.Index; + dragPerson.Index = dropPerson.Index; + dropPerson.Index = dragIndex; + } + private void Button_Click(object sender, RoutedEventArgs e) { MessageBox.Show("Done"); diff --git a/Software/Visual_Studio/Utilities/Tango.UITests/Tango.UITests.csproj b/Software/Visual_Studio/Utilities/Tango.UITests/Tango.UITests.csproj index 715b4a454..89be52796 100644 --- a/Software/Visual_Studio/Utilities/Tango.UITests/Tango.UITests.csproj +++ b/Software/Visual_Studio/Utilities/Tango.UITests/Tango.UITests.csproj @@ -98,6 +98,14 @@ <None Include="App.config" /> </ItemGroup> <ItemGroup> + <ProjectReference Include="..\..\Tango.Core\Tango.Core.csproj"> + <Project>{A34EE0F0-649D-41C8-8489-B6F1CC6924EE}</Project> + <Name>Tango.Core</Name> + </ProjectReference> + <ProjectReference Include="..\..\Tango.DragAndDrop\Tango.DragAndDrop.csproj"> + <Project>{b112d89a-a106-41ae-a0c1-4abc84c477f5}</Project> + <Name>Tango.DragAndDrop</Name> + </ProjectReference> <ProjectReference Include="..\..\Tango.SharedUI\Tango.SharedUI.csproj"> <Project>{8491d07b-c1f6-4b62-a412-41b9fd2d6538}</Project> <Name>Tango.SharedUI</Name> |
