diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-06-11 11:30:57 +0300 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-06-11 11:30:57 +0300 |
| commit | c4e821defadd93453b59200ea18784ea9d5dd630 (patch) | |
| tree | 13128f395711943fb3e6db99bee51588152219e1 /Software | |
| parent | 88477019255efb3ff02ba3de195741f1d49a925e (diff) | |
| download | Tango-c4e821defadd93453b59200ea18784ea9d5dd630.tar.gz Tango-c4e821defadd93453b59200ea18784ea9d5dd630.zip | |
Code Cleanup on Tango.Touch
Diffstat (limited to 'Software')
| -rw-r--r-- | Software/Visual_Studio/Tango.Touch/Controls/LightTouchDataGrid.cs | 57 | ||||
| -rw-r--r-- | Software/Visual_Studio/Tango.Touch/Controls/LightTouchDataGridColumn.cs | 22 |
2 files changed, 65 insertions, 14 deletions
diff --git a/Software/Visual_Studio/Tango.Touch/Controls/LightTouchDataGrid.cs b/Software/Visual_Studio/Tango.Touch/Controls/LightTouchDataGrid.cs index 259badb7a..9a612d2f1 100644 --- a/Software/Visual_Studio/Tango.Touch/Controls/LightTouchDataGrid.cs +++ b/Software/Visual_Studio/Tango.Touch/Controls/LightTouchDataGrid.cs @@ -11,6 +11,7 @@ using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; +using System.Windows.Controls.Primitives; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; @@ -33,6 +34,7 @@ namespace Tango.Touch.Controls private Random _rnd = new Random(); private const double touch_inertia_coefficiant = 10; private const double bounce_offset_max = 100; + private bool _isLoaded; #region Properties @@ -169,6 +171,7 @@ namespace Tango.Touch.Controls { _last_manipulation_deltas = new List<double>(); SortCommand = new RelayCommand<LightTouchDataGridColumn>(HandleSortCommand); + Loaded += LightTouchDataGrid_Loaded; } #endregion @@ -192,6 +195,8 @@ namespace Tango.Touch.Controls _grid_rows.ManipulationDelta += _grid_rows_ManipulationDelta; _grid_rows.ManipulationCompleted += _grid_rows_ManipulationCompleted; + + _items_control_rows.ItemContainerGenerator.StatusChanged += ItemContainerGenerator_StatusChanged; } #endregion @@ -239,7 +244,7 @@ namespace Tango.Touch.Controls if (_items_control_rows.Margin.Top > 0 || (_items_control_rows.Margin.Top - _grid_rows.ActualHeight < -_items_control_rows.ActualHeight)) { bounced = true; - FixMargins(); + SnapRowsToBounds(); } } }; @@ -319,7 +324,7 @@ namespace Tango.Touch.Controls e.TouchDevice.Capture(null); } - FixMargins(); + SnapRowsToBounds(); } } @@ -330,12 +335,10 @@ namespace Tango.Touch.Controls { if (ItemsSource != null) { - LayoutRows(); - if (ItemsSource is INotifyCollectionChanged) { - (ItemsSource as INotifyCollectionChanged).CollectionChanged -= LightTouchDataGrid_CollectionChanged; - (ItemsSource as INotifyCollectionChanged).CollectionChanged += LightTouchDataGrid_CollectionChanged; + (ItemsSource as INotifyCollectionChanged).CollectionChanged -= Items_Source_Collection_Changed; + (ItemsSource as INotifyCollectionChanged).CollectionChanged += Items_Source_Collection_Changed; } } } @@ -371,19 +374,38 @@ namespace Tango.Touch.Controls #region Event Handlers + private void LightTouchDataGrid_Loaded(object sender, RoutedEventArgs e) + { + _isLoaded = true; + LayoutRows(); + } + + private void ItemContainerGenerator_StatusChanged(object sender, EventArgs e) + { + if (_items_control_rows.ItemContainerGenerator.Status == GeneratorStatus.ContainersGenerated) + { + LayoutRows(); + } + } + /// <summary> - /// Handles the CollectionChanged event of the LightTouchDataGrid control. + /// Handles the CollectionChanged event of the ItemsSource if observable. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="NotifyCollectionChangedEventArgs"/> instance containing the event data.</param> - private void LightTouchDataGrid_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) + private void Items_Source_Collection_Changed(object sender, NotifyCollectionChangedEventArgs e) { LayoutRows(); } #endregion - private void FixMargins() + #region Private Methods + + /// <summary> + /// Snaps the items control if they are out of bounds. + /// </summary> + private void SnapRowsToBounds() { ThicknessAnimation ani = new ThicknessAnimation(); ani.Duration = TimeSpan.FromSeconds(0.2); @@ -401,11 +423,18 @@ namespace Tango.Touch.Controls } } + #endregion + + #region Public Methods + + /// <summary> + /// Lays out the rows on the canvas according to the current sort column. + /// </summary> public void LayoutRows() { - if (_items_control_rows == null) return; + if (_items_control_rows == null || !_isLoaded) return; - var rows = _items_control_rows.FindVisualChildren<TouchDataGridRow>().ToList(); + var rows = _items_control_rows.ItemContainerGenerator.Items.Select(x => _items_control_rows.ItemContainerGenerator.ContainerFromItem(x) as ContentPresenter).ToList(); var sortColumn = Columns.SingleOrDefault(x => x.SortDirection != null && x.SortMember != null); var first = rows.FirstOrDefault(); var ordered = rows.ToList(); @@ -431,7 +460,7 @@ namespace Tango.Touch.Controls for (int i = 0; i < ordered.Count; i++) { - UIElement uiElement = (UIElement)_items_control_rows.ItemContainerGenerator.ContainerFromIndex(rows.IndexOf(ordered[i])); + UIElement uiElement = ordered[i]; //if (double.IsNaN(Canvas.GetTop(uiElement))) //{ @@ -444,10 +473,12 @@ namespace Tango.Touch.Controls //uiElement.BeginAnimation(Canvas.TopProperty, ani); Canvas.SetTop(uiElement, current_top); - current_top += (rows[i].Margin.Top + rows[i].ActualHeight + rows[i].Margin.Bottom); + current_top += (ordered[i].Margin.Top + ordered[i].ActualHeight + ordered[i].Margin.Bottom); } _items_control_rows.Height = current_top; } + + #endregion } } diff --git a/Software/Visual_Studio/Tango.Touch/Controls/LightTouchDataGridColumn.cs b/Software/Visual_Studio/Tango.Touch/Controls/LightTouchDataGridColumn.cs index fb86b334a..d64844154 100644 --- a/Software/Visual_Studio/Tango.Touch/Controls/LightTouchDataGridColumn.cs +++ b/Software/Visual_Studio/Tango.Touch/Controls/LightTouchDataGridColumn.cs @@ -11,6 +11,11 @@ namespace Tango.Touch.Controls { public class LightTouchDataGridColumn : DependencyObject { + #region Properties + + /// <summary> + /// Gets or sets the width. + /// </summary> public GridLength Width { get { return (GridLength)GetValue(WidthProperty); } @@ -19,6 +24,9 @@ namespace Tango.Touch.Controls public static readonly DependencyProperty WidthProperty = DependencyProperty.Register("Width", typeof(GridLength), typeof(LightTouchDataGridColumn), new PropertyMetadata(new GridLength(1, GridUnitType.Star))); + /// <summary> + /// Gets or sets the cell template. + /// </summary> public DataTemplate CellTemplate { get { return (DataTemplate)GetValue(CellTemplateProperty); } @@ -27,6 +35,9 @@ namespace Tango.Touch.Controls public static readonly DependencyProperty CellTemplateProperty = DependencyProperty.Register("CellTemplate", typeof(DataTemplate), typeof(LightTouchDataGridColumn), new PropertyMetadata(null)); + /// <summary> + /// Gets or sets the header template. + /// </summary> public DataTemplate HeaderTemplate { get { return (DataTemplate)GetValue(HeaderTemplateProperty); } @@ -35,6 +46,9 @@ namespace Tango.Touch.Controls public static readonly DependencyProperty HeaderTemplateProperty = DependencyProperty.Register("HeaderTemplate", typeof(DataTemplate), typeof(LightTouchDataGridColumn), new PropertyMetadata(null)); + /// <summary> + /// Gets or sets the sort direction. + /// </summary> public ListSortDirection? SortDirection { get { return (ListSortDirection?)GetValue(SortDirectionProperty); } @@ -43,6 +57,9 @@ namespace Tango.Touch.Controls public static readonly DependencyProperty SortDirectionProperty = DependencyProperty.Register("SortDirection", typeof(ListSortDirection?), typeof(LightTouchDataGridColumn), new PropertyMetadata(null)); + /// <summary> + /// Gets or sets the foreground. + /// </summary> public Brush Foreground { get { return (Brush)GetValue(ForegroundProperty); } @@ -51,6 +68,9 @@ namespace Tango.Touch.Controls public static readonly DependencyProperty ForegroundProperty = DependencyProperty.Register("Foreground", typeof(Brush), typeof(LightTouchDataGrid), new PropertyMetadata(Brushes.Black)); + /// <summary> + /// Gets or sets the sort member. + /// </summary> public String SortMember { get { return (String)GetValue(SortMemberProperty); } @@ -59,6 +79,6 @@ namespace Tango.Touch.Controls public static readonly DependencyProperty SortMemberProperty = DependencyProperty.Register("SortMember", typeof(String), typeof(LightTouchDataGrid), new PropertyMetadata(null)); - + #endregion } } |
