aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.Touch/Controls/TouchNotificationBar.cs
diff options
context:
space:
mode:
authorMirta <mirta@twine-s.com>2020-12-30 16:39:52 +0200
committerMirta <mirta@twine-s.com>2020-12-30 16:39:52 +0200
commit00a491d93733d4625ad329b2ba8237f445364b3f (patch)
tree4b24c6fa78d7648f4bb7cefafa464bb0b063fec4 /Software/Visual_Studio/Tango.Touch/Controls/TouchNotificationBar.cs
parent124ad4150f80c6846fdee41dbbda9848c105f6e5 (diff)
downloadTango-00a491d9.tar.gz
Tango-00a491d9.zip
merge
Diffstat (limited to 'Software/Visual_Studio/Tango.Touch/Controls/TouchNotificationBar.cs')
-rw-r--r--Software/Visual_Studio/Tango.Touch/Controls/TouchNotificationBar.cs198
1 files changed, 122 insertions, 76 deletions
diff --git a/Software/Visual_Studio/Tango.Touch/Controls/TouchNotificationBar.cs b/Software/Visual_Studio/Tango.Touch/Controls/TouchNotificationBar.cs
index 8ed4ead69..ef7e24ff4 100644
--- a/Software/Visual_Studio/Tango.Touch/Controls/TouchNotificationBar.cs
+++ b/Software/Visual_Studio/Tango.Touch/Controls/TouchNotificationBar.cs
@@ -27,7 +27,6 @@ namespace Tango.Touch.Controls
public class TouchNotificationBar : ContentControl
{
private const double HEIGHT_RATIO = 0.75;
- private const double DRAGPATH_HEIGH = 20.0;
private bool _isMouseDown;
private Point _mouseDownLocation;
@@ -48,9 +47,18 @@ namespace Tango.Touch.Controls
private Grid _notification_counter_grid;
private LightTouchScrollViewer _scrollViewer;
+ static TouchNotificationBar()
+ {
+ DefaultStyleKeyProperty.OverrideMetadata(typeof(TouchNotificationBar), new FrameworkPropertyMetadata(typeof(TouchNotificationBar)));
+ }
-
- #region Dep_Properties
+ public String ItemExpandedPropertyPath
+ {
+ get { return (String)GetValue(ItemExpandedPropertyPathProperty); }
+ set { SetValue(ItemExpandedPropertyPathProperty, value); }
+ }
+ public static readonly DependencyProperty ItemExpandedPropertyPathProperty =
+ DependencyProperty.Register("ItemExpandedPropertyPath", typeof(String), typeof(TouchNotificationBar), new PropertyMetadata(null));
public bool HasNotifications
{
@@ -107,18 +115,8 @@ namespace Tango.Touch.Controls
}
public static readonly DependencyProperty NotificationBarVisibilityProperty =
DependencyProperty.Register("NotificationBarVisibility", typeof(Visibility), typeof(TouchNotificationBar), new PropertyMetadata(Visibility.Visible));
-
- #endregion
-
- #region constructors
-
- static TouchNotificationBar()
- {
- DefaultStyleKeyProperty.OverrideMetadata(typeof(TouchNotificationBar), new FrameworkPropertyMetadata(typeof(TouchNotificationBar)));
- }
public TouchNotificationBar()
{
- IsExpanded = false;
Loaded += TouchNotificationBar_Loaded;
NotificationPressedCommand = new RelayCommand(() =>
@@ -130,10 +128,10 @@ namespace Tango.Touch.Controls
});
}
- #endregion
-
-
- #region Override_Base
+ private void TouchNotificationBar_Loaded(object sender, RoutedEventArgs e)
+ {
+ _border_drag.MaxHeight = ActualHeight;
+ }
public override void OnApplyTemplate()
{
@@ -145,121 +143,169 @@ namespace Tango.Touch.Controls
_items_control = GetTemplateChild("PART_ItemsControl") as ItemsControl;
_notification_counter_grid = GetTemplateChild("PART_NotificationCounterGrid") as Grid;
_scrollViewer = GetTemplateChild("PART_ScrollViewer") as LightTouchScrollViewer;
-
+
+ //border_notifications.IsManipulationEnabled = true;
_border_drag.RegisterForPreviewMouseOrTouchDown(GridNotificationMouseDown);
_border_drag.RegisterForMouseOrTouchMove(GridNotificationMouseMove);
_border_drag.RegisterForPreviewMouseOrTouchUp(GridNotificationMouseUp);
- _border_drag.SizeChanged += Drag_Border_SizeChanged;
+ _border_drag.SizeChanged += Drag_Border_SizeChanged;
+ _items_control.ItemContainerGenerator.StatusChanged += ItemContainerGenerator_StatusChanged;
}
- #endregion
+ private void ItemContainerGenerator_StatusChanged(object sender, EventArgs e)
+ {
+ if (_items_control.ItemContainerGenerator.Status == System.Windows.Controls.Primitives.GeneratorStatus.ContainersGenerated)
+ {
+ if (_items_control.Items.Count > 0)
+ {
+ var element = _items_control.ItemContainerGenerator.ContainerFromIndex(0) as FrameworkElement;
+ if (element != null)
+ {
+ element.RegisterForLoadedOrNow((x, y) =>
+ {
+ CurrentMinHeight = element.ActualHeight;
+ ResizeNotification(element);
+ });
+ }
+ }
+ else
+ {
+ CurrentMinHeight = 0;
+ }
+ }
+ }
private FrameworkElement GetLastNotification()
{
return _items_control.ItemContainerGenerator.ContainerFromIndex(0) as FrameworkElement;
}
- private void TouchNotificationBar_Loaded(object sender, RoutedEventArgs e)
- {
- _border_drag.MaxHeight = ActualHeight;
- }
private void Drag_Border_SizeChanged(object sender, SizeChangedEventArgs e)
{
_grid_mask.Opacity = _border_drag.ActualHeight / ActualHeight;
- if (e.NewSize.Height > CurrentMinHeight && CurrentMinHeight > 0 )
+ ResizeNotifications();
+
+ if (e.NewSize.Height > CurrentMinHeight && CurrentMinHeight > 0)
{
_notification_counter_grid.Visibility = Visibility.Hidden;
}
- else if(Notifications.Count > 1 && CurrentMinHeight > 0)
+ else
{
_notification_counter_grid.Visibility = Visibility.Visible;
}
}
- /// <summary>
- /// Called when has notifications items or all items removed
- /// </summary>
- private void OnHasNotificationsChanged()
+ private void ResizeNotifications()
{
- if (HasNotifications)
+ for (int i = 0; i < _items_control.Items.Count; i++)
{
- UpdateMinHeightByDispalyedItem();
+ FrameworkElement element = _items_control.ItemContainerGenerator.ContainerFromIndex(i) as FrameworkElement;
+ ResizeNotification(element);
}
- else
+ }
+
+ private void ResizeNotification(FrameworkElement element)
+ {
+ var control = element.FindChild<UserControl>();
+
+ if (control != null && !double.IsNaN(_border_drag.Height))
{
- CurrentMinHeight = 0;
- if (IsExpanded)
- {
- CloseNotifications();
- }
- _border_notifications.Height = CurrentMinHeight;
- _grid_container.MinHeight = 0;
- _grid_container.Height = 0;
+ control.Height = ((_border_drag.Height - CurrentMinHeight) / ActualHeight) * (control.MaxHeight - control.MinHeight) + control.MinHeight;
}
}
- private void UpdateMinHeightByDispalyedItem()
+ private void OnHasNotificationsChanged()
{
- var last = GetLastNotification();
- if(last != null)
+ DoubleAnimation ani = new DoubleAnimation();
+ ani.Duration = TimeSpan.FromSeconds(0.2);
+
+ _grid_container.EnsureHeight();
+
+ if (HasNotifications)
{
- last.RegisterForLoadedOrNow((x, y) =>
+ var last = GetLastNotification();
+
+ last.RegisterForLoadedOrNow((x, e) =>
{
- CurrentMinHeight = last.ActualHeight;
+ ani.To = last.ActualHeight;
+ _grid_container.BeginAnimation(Grid.HeightProperty, ani);
_border_notifications.Height = last.ActualHeight;
- _grid_container.MinHeight = last.ActualHeight;
- _grid_container.Height = CurrentMinHeight;
});
}
+ else
+ {
+ CurrentMinHeight = 0;
+ ani.To = 0;
+ CloseNotifications();
+ _grid_container.BeginAnimation(Grid.HeightProperty, ani);
+ }
}
- /// <summary>
- /// Callback function on Notifications property
- /// </summary>
- private void OnNotificationsChanged()
+
+ private void OnNotificationsChanged()
{
+ UpdateExpanded(IsExpanded);
+
if (Notifications is INotifyCollectionChanged)
{
- (Notifications as INotifyCollectionChanged).CollectionChanged += (_, e) =>
+ (Notifications as INotifyCollectionChanged).CollectionChanged += (_, __) =>
{
this.BeginInvoke(() =>
{
- if(Notifications.Count > 0)
- {
- UpdateMinHeightByDispalyedItem();
- }
- if (IsExpanded == false && Notifications.Count > 1)
- {
- _notification_counter_grid.Visibility = Visibility.Visible;
- }
- else
- {
- _notification_counter_grid.Visibility = Visibility.Hidden;
- }
+ UpdateExpanded(IsExpanded);
});
- };
-
+ };
}
}
-
- #region Mouse handlers
+
+ private void UpdateExpanded(bool expanded)
+ {
+ if (ItemExpandedPropertyPath != null)
+ {
+ foreach (var item in Notifications.Cast<Object>().ToList())
+ {
+ item.SetPropertyValueByPath(ItemExpandedPropertyPath, expanded);
+ }
+ }
+ }
+
private void OpenNotifications()
{
+ _border_drag.EnsureHeight();
+ _border_notifications.EnsureHeight();
+
_border_drag.StartDoubleAnimation(Border.HeightProperty, TimeSpan.FromSeconds(0.2), _border_drag.MaxHeight, null, null, 1, () =>
- {
- IsExpanded = true;
- });
+ {
+ IsExpanded = true;
+ });
_border_notifications.StartDoubleAnimation(Border.HeightProperty, TimeSpan.FromSeconds(0.2), ActualHeight * HEIGHT_RATIO, null, null, 1);
+
+ UpdateExpanded(true);
}
private void CloseNotifications()
{
+ _border_drag.EnsureHeight();
+ _border_notifications.EnsureHeight();
+
_border_notifications.StartDoubleAnimation(Border.HeightProperty, TimeSpan.FromSeconds(0.2), CurrentMinHeight, null, 1, null, () =>
{
_border_notifications.BeginAnimation(Border.HeightProperty, null);
_border_notifications.Height = CurrentMinHeight;
+
+ for (int i = 0; i < _items_control.Items.Count; i++)
+ {
+ FrameworkElement element = _items_control.ItemContainerGenerator.ContainerFromIndex(i) as FrameworkElement;
+
+ var control = element.FindChild<UserControl>();
+
+ if (control != null)
+ {
+ control.Height = control.MinHeight;
+ }
+ }
});
_border_drag.StartDoubleAnimation(Border.HeightProperty, TimeSpan.FromSeconds(0.2), CurrentMinHeight, null, 1, null, () =>
@@ -272,7 +318,9 @@ namespace Tango.Touch.Controls
tAni.Duration = TimeSpan.FromSeconds(0.3);
tAni.To = new Thickness(0);
_border_notifications.BeginAnimation(Border.BorderThicknessProperty, tAni);
-
+
+ UpdateExpanded(false);
+
IsExpanded = false;
Task.Delay(400).ContinueWith((x) =>
@@ -365,7 +413,7 @@ namespace Tango.Touch.Controls
if (_border_notifications.ActualHeight > CurrentMinHeight)
{
- _border_notifications.BorderThickness = new Thickness(0, 0, 0, DRAGPATH_HEIGH);
+ _border_notifications.BorderThickness = new Thickness(0, 0, 0, 20);
}
else
{
@@ -388,7 +436,5 @@ namespace Tango.Touch.Controls
_isMouseDown = true;
}
}
-
- #endregion
}
}