From 58f612e03a9bb31c2ada4eb3c5989be458ec4ff5 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Mon, 2 Jul 2018 14:36:16 +0300 Subject: Implemented Twine Catalog Control. Implemented TouchStaticListBox. Added Scrollbar visibility, GetMostVisibleElement, Scrolling event - to LightTouchScrollviewer. --- .../Controls/TwineCatalogControl.xaml | 12 -- .../Controls/TwineCatalogControl.xaml.cs | 28 ----- .../Modules/Tango.PPC.Jobs/Tango.PPC.Jobs.csproj | 7 -- .../Controls/TwineCatalogControl.xaml | 57 ++++++++-- .../Controls/TwineCatalogControl.xaml.cs | 60 +++++++++- .../PPC/Tango.PPC.Common/Resources/Styles.xaml | 41 +++++++ .../Controls/DoubleValueChangedEventArgs.cs | 19 ++++ .../Tango.Touch/Controls/LightTouchScrollViewer.cs | 96 ++++++++++++++++ .../Controls/LightTouchScrollViewer.xaml | 76 ++++++------- .../Tango.Touch/Controls/TouchListBox.cs | 7 ++ .../Tango.Touch/Controls/TouchListBox.xaml | 2 +- .../Tango.Touch/Controls/TouchStaticListBox.cs | 122 +++++++++++++++++++++ .../Tango.Touch/Controls/TouchStaticListBox.xaml | 38 +++++++ .../Visual_Studio/Tango.Touch/Tango.Touch.csproj | 6 + .../Visual_Studio/Tango.Touch/Themes/Generic.xaml | 1 + 15 files changed, 475 insertions(+), 97 deletions(-) delete mode 100644 Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Controls/TwineCatalogControl.xaml delete mode 100644 Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Controls/TwineCatalogControl.xaml.cs create mode 100644 Software/Visual_Studio/Tango.Touch/Controls/DoubleValueChangedEventArgs.cs create mode 100644 Software/Visual_Studio/Tango.Touch/Controls/TouchStaticListBox.cs create mode 100644 Software/Visual_Studio/Tango.Touch/Controls/TouchStaticListBox.xaml (limited to 'Software/Visual_Studio') diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Controls/TwineCatalogControl.xaml b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Controls/TwineCatalogControl.xaml deleted file mode 100644 index 51917b594..000000000 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Controls/TwineCatalogControl.xaml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Controls/TwineCatalogControl.xaml.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Controls/TwineCatalogControl.xaml.cs deleted file mode 100644 index b1a109a75..000000000 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Controls/TwineCatalogControl.xaml.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; - -namespace Tango.PPC.Jobs.Controls -{ - /// - /// Interaction logic for TwineCatalogControl.xaml - /// - public partial class TwineCatalogControl : UserControl - { - public TwineCatalogControl() - { - InitializeComponent(); - } - } -} diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Tango.PPC.Jobs.csproj b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Tango.PPC.Jobs.csproj index 7e8dc94b3..f77a47d37 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Tango.PPC.Jobs.csproj +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Tango.PPC.Jobs.csproj @@ -72,10 +72,6 @@ Designer MSBuild:Compile - - Designer - MSBuild:Compile - MSBuild:Compile Designer @@ -112,9 +108,6 @@ JobSummeryViewer.xaml - - TwineCatalogControl.xaml - diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Controls/TwineCatalogControl.xaml b/Software/Visual_Studio/PPC/Tango.PPC.Common/Controls/TwineCatalogControl.xaml index 142e1a10c..cc28bfddb 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Controls/TwineCatalogControl.xaml +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Controls/TwineCatalogControl.xaml @@ -15,27 +15,64 @@ - - + + - - + + - - + + + + + - - + + @@ -79,10 +116,10 @@ - + - + diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Controls/TwineCatalogControl.xaml.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Controls/TwineCatalogControl.xaml.cs index ad1c8b50c..2b376e855 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Controls/TwineCatalogControl.xaml.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Controls/TwineCatalogControl.xaml.cs @@ -22,24 +22,80 @@ namespace Tango.PPC.Common.Controls public partial class TwineCatalogControl : UserControl { private Catalog _catalog; + private bool _loaded; + private bool _preventChange; + + public CatalogItem SelectedItem + { + get { return (CatalogItem)GetValue(SelectedItemProperty); } + set { SetValue(SelectedItemProperty, value); } + } + public static readonly DependencyProperty SelectedItemProperty = + DependencyProperty.Register("SelectedItem", typeof(CatalogItem), typeof(TwineCatalogControl), new PropertyMetadata(null,(d,e) => (d as TwineCatalogControl).OnSelectedItemChanged())); public TwineCatalogControl() { InitializeComponent(); + Loaded += TwineCatalogControl_Loaded; DataContextChanged += (x, y) => { _catalog = DataContext as Catalog; }; } + private void ScrollViewer_Scrolling(object sender, Touch.Controls.DoubleValueChangedEventArgs e) + { + if (!_preventChange) + { + var group = list.ScrollViewer.GetMostVisibleElementDataContext(); + + if (group != null) + { + _preventChange = true; + slider.Value = slider.Maximum - _catalog.Groups.IndexOf(group); + _preventChange = false; + } + } + } + private void TwineCatalogControl_Loaded(object sender, RoutedEventArgs e) { - + if (!_loaded) + { + list.ScrollViewer.Scrolling += ScrollViewer_Scrolling; + + _preventChange = true; + slider.Value = slider.Maximum; + _preventChange = false; + _loaded = true; + } } private void TouchSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs e) { + if (!_preventChange) + { + if (_catalog != null) + { + _preventChange = true; + list.ScrollToItem(_catalog.Groups.ElementAt(_catalog.Groups.Count - 1 - (int)e.NewValue)); + _preventChange = false; + } + } + if (_catalog != null) { - list.ScrollToItem(_catalog.Groups.ElementAt(_catalog.Groups.Count - 1 - (int)e.NewValue)); + slider.Foreground = new SolidColorBrush(_catalog.Groups.ElementAt(_catalog.Groups.Count - 1 - (int)e.NewValue).Color); + } + } + + private void OnSelectedItemChanged() + { + if (!_preventChange) + { + _preventChange = true; + var item = SelectedItem; + SelectedItem = null; + SelectedItem = item; + _preventChange = false; } } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Resources/Styles.xaml b/Software/Visual_Studio/PPC/Tango.PPC.Common/Resources/Styles.xaml index adea1481c..426372688 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Resources/Styles.xaml +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Resources/Styles.xaml @@ -2,5 +2,46 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:touch="clr-namespace:Tango.Touch.Controls;assembly=Tango.Touch" xmlns:local="clr-namespace:Tango.PPC.Common.Resources"> + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/Tango.Touch/Controls/DoubleValueChangedEventArgs.cs b/Software/Visual_Studio/Tango.Touch/Controls/DoubleValueChangedEventArgs.cs new file mode 100644 index 000000000..2e1b894a9 --- /dev/null +++ b/Software/Visual_Studio/Tango.Touch/Controls/DoubleValueChangedEventArgs.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; + +namespace Tango.Touch.Controls +{ + public class DoubleValueChangedEventArgs : RoutedEventArgs + { + public double Value { get; set; } + + public DoubleValueChangedEventArgs(RoutedEvent routedEvent, object source, double value) : base(routedEvent, source) + { + Value = value; + } + } +} diff --git a/Software/Visual_Studio/Tango.Touch/Controls/LightTouchScrollViewer.cs b/Software/Visual_Studio/Tango.Touch/Controls/LightTouchScrollViewer.cs index 8d1504f48..9840a6fd8 100644 --- a/Software/Visual_Studio/Tango.Touch/Controls/LightTouchScrollViewer.cs +++ b/Software/Visual_Studio/Tango.Touch/Controls/LightTouchScrollViewer.cs @@ -38,8 +38,32 @@ namespace Tango.Touch.Controls private const double _friction_factor_per_second = 0.9; private DispatcherTimer _move_timer; + #region Events + + public delegate void ScrollingEventHandler(object sender, DoubleValueChangedEventArgs e); + + public static readonly RoutedEvent ScrollingEvent = EventManager.RegisterRoutedEvent("Scrolling", RoutingStrategy.Bubble, typeof(ScrollingEventHandler), typeof(LightTouchScrollViewer)); + /// + /// Occurs when the scrolling position has changed. + /// + public event ScrollingEventHandler Scrolling + { + add { AddHandler(ScrollingEvent, value); } + remove { RemoveHandler(ScrollingEvent, value); } + } + + #endregion + #region Properties + public Thickness InternalMargin + { + get { return (Thickness)GetValue(InternalMarginProperty); } + set { SetValue(InternalMarginProperty, value); } + } + public static readonly DependencyProperty InternalMarginProperty = + DependencyProperty.Register("InternalMargin", typeof(Thickness), typeof(LightTouchScrollViewer), new PropertyMetadata(default(Thickness), (d, e) => (d as LightTouchScrollViewer).RaiseScrollEvent())); + /// /// Gets or sets the scroll bar margins. @@ -164,6 +188,16 @@ namespace Tango.Touch.Controls public static readonly DependencyProperty DisableScrollingProperty = DependencyProperty.Register("DisableScrolling", typeof(bool), typeof(LightTouchScrollViewer), new PropertyMetadata(false)); + /// + /// Gets or sets the scroll bar visibility. + /// + public Visibility ScrollBarVisibility + { + get { return (Visibility)GetValue(ScrollBarVisibilityProperty); } + set { SetValue(ScrollBarVisibilityProperty, value); } + } + public static readonly DependencyProperty ScrollBarVisibilityProperty = + DependencyProperty.Register("ScrollBarVisibility", typeof(Visibility), typeof(LightTouchScrollViewer), new PropertyMetadata(Visibility.Visible)); #endregion @@ -204,6 +238,8 @@ namespace Tango.Touch.Controls _thumb.DragDelta += _thumb_DragDelta; _thumb.DragStarted += _thumb_DragStarted; _thumb.DragCompleted += _thumb_DragCompleted; + + this.Bind(InternalMarginProperty, _grid_content, Grid.MarginProperty, System.Windows.Data.BindingMode.OneWay); } private void _thumb_DragCompleted(object sender, DragCompletedEventArgs e) @@ -630,6 +666,21 @@ namespace Tango.Touch.Controls } } + private Rect GetViewPortRect() + { + return new Rect(0, -_grid_content.Margin.Top, _border_viewport.ActualWidth, _border_viewport.ActualHeight); + } + + private Rect GetElementRect(FrameworkElement element) + { + if (element != null) + { + return new Rect(element.TranslatePoint(new Point(0, 0), _grid_content), new Size(element.ActualWidth, element.ActualHeight)); + } + + return new Rect(); + } + #endregion #region Public Methods @@ -710,6 +761,51 @@ namespace Tango.Touch.Controls } } + /// + /// Gets the most visible element. + /// + /// + public FrameworkElement GetMostVisibleElement() + { + var elements = _grid_content.FindVisualChildren().ToList(); + + if (elements.Count > 0) + { + var viewPort = GetViewPortRect(); + var mostVisible = elements.OrderBy(x => Rect.Intersect(viewPort, GetElementRect(x)).Height).Last(); + return mostVisible; + } + + return null; + } + + public T GetMostVisibleElementDataContext() where T : class + { + var elements = _grid_content.FindVisualChildren().Where(x => x.DataContext is T).ToList(); + + if (elements.Count > 0) + { + var viewPort = GetViewPortRect(); + var mostVisible = elements.OrderBy(x => Rect.Intersect(viewPort, GetElementRect(x)).Height).Last(); + return mostVisible.DataContext as T; + } + + return null; + } + + #endregion + + #region Virtual Methods + + /// + /// Raises the scroll event. + /// + protected virtual void RaiseScrollEvent() + { + DoubleValueChangedEventArgs e = new DoubleValueChangedEventArgs(ScrollingEvent, this, GetScrollPosition()); + RaiseEvent(e); + } + #endregion } } diff --git a/Software/Visual_Studio/Tango.Touch/Controls/LightTouchScrollViewer.xaml b/Software/Visual_Studio/Tango.Touch/Controls/LightTouchScrollViewer.xaml index c7cd71066..51738c299 100644 --- a/Software/Visual_Studio/Tango.Touch/Controls/LightTouchScrollViewer.xaml +++ b/Software/Visual_Studio/Tango.Touch/Controls/LightTouchScrollViewer.xaml @@ -67,46 +67,48 @@ - - - - - - - - - - - - - + + + + - - - - + + + + + + + + + + + + + + + diff --git a/Software/Visual_Studio/Tango.Touch/Controls/TouchListBox.cs b/Software/Visual_Studio/Tango.Touch/Controls/TouchListBox.cs index 6512f796f..ac446b9fd 100644 --- a/Software/Visual_Studio/Tango.Touch/Controls/TouchListBox.cs +++ b/Software/Visual_Studio/Tango.Touch/Controls/TouchListBox.cs @@ -129,6 +129,13 @@ namespace Tango.Touch.Controls public static readonly DependencyProperty DisableRippleProperty = DependencyProperty.Register("DisableRipple", typeof(bool), typeof(TouchListBox), new PropertyMetadata(false)); + public Visibility ScrollBarVisibility + { + get { return (Visibility)GetValue(ScrollBarVisibilityProperty); } + set { SetValue(ScrollBarVisibilityProperty, value); } + } + public static readonly DependencyProperty ScrollBarVisibilityProperty = + DependencyProperty.Register("ScrollBarVisibility", typeof(Visibility), typeof(TouchListBox), new PropertyMetadata(Visibility.Visible)); public TouchListBox() diff --git a/Software/Visual_Studio/Tango.Touch/Controls/TouchListBox.xaml b/Software/Visual_Studio/Tango.Touch/Controls/TouchListBox.xaml index be03f498c..92279d5e6 100644 --- a/Software/Visual_Studio/Tango.Touch/Controls/TouchListBox.xaml +++ b/Software/Visual_Studio/Tango.Touch/Controls/TouchListBox.xaml @@ -36,7 +36,7 @@ - + diff --git a/Software/Visual_Studio/Tango.Touch/Controls/TouchStaticListBox.cs b/Software/Visual_Studio/Tango.Touch/Controls/TouchStaticListBox.cs new file mode 100644 index 000000000..febd09309 --- /dev/null +++ b/Software/Visual_Studio/Tango.Touch/Controls/TouchStaticListBox.cs @@ -0,0 +1,122 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; +using Tango.Core.Commands; +using Tango.Core.EventArguments; + +namespace Tango.Touch.Controls +{ + public class TouchStaticListBox : Control + { + public IList ItemsSource + { + get { return (IList)GetValue(ItemsSourceProperty); } + set { SetValue(ItemsSourceProperty, value); } + } + public static readonly DependencyProperty ItemsSourceProperty = + DependencyProperty.Register("ItemsSource", typeof(IList), typeof(TouchStaticListBox), new PropertyMetadata(null)); + + public DataTemplate ItemTemplate + { + get { return (DataTemplate)GetValue(ItemTemplateProperty); } + set { SetValue(ItemTemplateProperty, value); } + } + public static readonly DependencyProperty ItemTemplateProperty = + DependencyProperty.Register("ItemTemplate", typeof(DataTemplate), typeof(TouchStaticListBox), new PropertyMetadata(null)); + + public Style ItemContainerStyle + { + get { return (Style)GetValue(ItemContainerStyleProperty); } + set { SetValue(ItemContainerStyleProperty, value); } + } + public static readonly DependencyProperty ItemContainerStyleProperty = + DependencyProperty.Register("ItemContainerStyle", typeof(Style), typeof(TouchStaticListBox), new PropertyMetadata(null)); + + public Object SelectedItem + { + get { return (Object)GetValue(SelectedItemProperty); } + set { SetValue(SelectedItemProperty, value); } + } + public static readonly DependencyProperty SelectedItemProperty = + DependencyProperty.Register("SelectedItem", typeof(Object), typeof(TouchStaticListBox), new PropertyMetadata(null, (d, e) => (d as TouchStaticListBox).OnSelectdItemChanged())); + + public RelayCommand ListBoxItemLoadedCommand + { + get { return (RelayCommand)GetValue(ListBoxItemLoadedCommandProperty); } + set { SetValue(ListBoxItemLoadedCommandProperty, value); } + } + public static readonly DependencyProperty ListBoxItemLoadedCommandProperty = + DependencyProperty.Register("ListBoxItemLoadedCommand", typeof(RelayCommand), typeof(TouchStaticListBox), new PropertyMetadata(null)); + + public ItemsPanelTemplate ItemsPanel + { + get { return (ItemsPanelTemplate)GetValue(ItemsPanelProperty); } + set { SetValue(ItemsPanelProperty, value); } + } + public static readonly DependencyProperty ItemsPanelProperty = + DependencyProperty.Register("ItemsPanel", typeof(ItemsPanelTemplate), typeof(TouchStaticListBox), new PropertyMetadata(null)); + + + + static TouchStaticListBox() + { + DefaultStyleKeyProperty.OverrideMetadata(typeof(TouchStaticListBox), new FrameworkPropertyMetadata(typeof(TouchStaticListBox))); + } + + public TouchStaticListBox() + { + ListBoxItemLoadedCommand = new RelayCommand(RegisterListBoxItemEvents); + } + + private void RegisterListBoxItemEvents(TouchListBoxItem item) + { + if (item.Tag == null) + { + item.Tag = 1; + item.RegisterForPreviewMouseOrTouchUp(OnItemMouseUp); + } + } + + private void OnItemMouseUp(object sender, MouseOrTouchEventArgs e) + { + var scrollViewer = this.FindAncestor(); + if (scrollViewer != null && scrollViewer.IsAfterScrolling) return; + + var item = (e.Source is TouchListBoxItem) ? e.Source as TouchListBoxItem : (e.Source as DependencyObject).FindAncestor(); + SelectedItem = item.DataContext; + } + + private void OnSelectdItemChanged() + { + var items = GetItems(); + items.ForEach(x => x.IsSelected = false); + + if (SelectedItem != null) + { + var selected_item = items.FirstOrDefault(x => x.DataContext == SelectedItem); + + if (selected_item != null) + { + selected_item.IsSelected = true; + } + } + } + + private List GetItems() + { + return this.FindVisualChildren().ToList(); + } + } +} diff --git a/Software/Visual_Studio/Tango.Touch/Controls/TouchStaticListBox.xaml b/Software/Visual_Studio/Tango.Touch/Controls/TouchStaticListBox.xaml new file mode 100644 index 000000000..6789a0e21 --- /dev/null +++ b/Software/Visual_Studio/Tango.Touch/Controls/TouchStaticListBox.xaml @@ -0,0 +1,38 @@ + + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/Tango.Touch/Tango.Touch.csproj b/Software/Visual_Studio/Tango.Touch/Tango.Touch.csproj index 9239f3298..b6242dfa2 100644 --- a/Software/Visual_Studio/Tango.Touch/Tango.Touch.csproj +++ b/Software/Visual_Studio/Tango.Touch/Tango.Touch.csproj @@ -60,6 +60,7 @@ Core.cs + @@ -75,6 +76,7 @@ + @@ -177,6 +179,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + Designer MSBuild:Compile diff --git a/Software/Visual_Studio/Tango.Touch/Themes/Generic.xaml b/Software/Visual_Studio/Tango.Touch/Themes/Generic.xaml index 73aa394ed..3a2c21a28 100644 --- a/Software/Visual_Studio/Tango.Touch/Themes/Generic.xaml +++ b/Software/Visual_Studio/Tango.Touch/Themes/Generic.xaml @@ -35,6 +35,7 @@ + -- cgit v1.3.1