diff options
| author | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-03-11 03:41:20 +0200 |
|---|---|---|
| committer | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-03-11 03:41:20 +0200 |
| commit | e774f9a90fd812a9de8c3efe966a759bee8be703 (patch) | |
| tree | da7a59af6af40ff810254df9e08f6a0f5a31fe1c /Software/Visual_Studio/Tango.SharedUI | |
| parent | eb793f20dc078a304a423a481e5bb0eddce71471 (diff) | |
| download | Tango-e774f9a90fd812a9de8c3efe966a759bee8be703.tar.gz Tango-e774f9a90fd812a9de8c3efe966a759bee8be703.zip | |
Working on FSE/PPC performance provider.
Implemented resolution service.
a lot of work!
Diffstat (limited to 'Software/Visual_Studio/Tango.SharedUI')
6 files changed, 225 insertions, 7 deletions
diff --git a/Software/Visual_Studio/Tango.SharedUI/Binding/BindingEventArgs.cs b/Software/Visual_Studio/Tango.SharedUI/Binding/BindingEventArgs.cs new file mode 100644 index 000000000..06ea61019 --- /dev/null +++ b/Software/Visual_Studio/Tango.SharedUI/Binding/BindingEventArgs.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Media; + +namespace Tango.SharedUI +{ + /// <summary> + /// Represents the <see cref="BindingEventContainer.ValueChanged"/> event arguments. + /// </summary> + /// <seealso cref="System.EventArgs" /> + public class BindingEventArgs : EventArgs + { + internal Action _renewAction; + + /// <summary> + /// Gets or sets the element. + /// </summary> + public DependencyObject DependencyObject { get; set; } + + /// <summary> + /// Gets or sets the binding property. + /// </summary> + public BindingProperty BindingProperty { get; set; } + + /// <summary> + /// Gets or sets the value. + /// </summary> + public Object Value { get; set; } + + public void Renew() + { + _renewAction?.Invoke(); + } + } +} diff --git a/Software/Visual_Studio/Tango.SharedUI/Binding/BindingEventContainer.cs b/Software/Visual_Studio/Tango.SharedUI/Binding/BindingEventContainer.cs new file mode 100644 index 000000000..a74a9b085 --- /dev/null +++ b/Software/Visual_Studio/Tango.SharedUI/Binding/BindingEventContainer.cs @@ -0,0 +1,95 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Data; +using System.Windows.Media; + +namespace Tango.SharedUI +{ + /// <summary> + /// Represents a binding event container. + /// </summary> + /// <seealso cref="System.Windows.DependencyObject" /> + public class BindingEventContainer : DependencyObject + { + private Action _renewAction; + + /// <summary> + /// Occurs when the dependency property value has changed. + /// </summary> + public event EventHandler<BindingEventArgs> ValueChanged; + + /// <summary> + /// Gets or sets the value. + /// </summary> + public Object Value + { + get { return (Object)GetValue(ValueProperty); } + set { SetValue(ValueProperty, value); } + } + public static readonly DependencyProperty ValueProperty = + DependencyProperty.Register("Value", typeof(Object), typeof(BindingEventContainer), new PropertyMetadata(null, (d, e) => (d as BindingEventContainer).OnValueChanged())); + + /// <summary> + /// Gets or sets the binding property. + /// </summary> + public BindingProperty BindingProperty { get; set; } + + /// <summary> + /// Gets or sets the dependency object. + /// </summary> + public DependencyObject DependencyObject { get; set; } + + /// <summary> + /// Initializes a new instance of the <see cref="BindingEventContainer"/> class. + /// </summary> + /// <param name="takeElement">The dependency object.</param> + /// <param name="bindingProperty">The binding property.</param> + public BindingEventContainer(DependencyObject dependencyObject, BindingProperty bindingProperty) + { + DependencyObject = dependencyObject; + BindingProperty = bindingProperty; + } + + /// <summary> + /// Called when the value has been changed + /// </summary> + protected virtual void OnValueChanged() + { + ValueChanged?.Invoke(this, new BindingEventArgs() + { + BindingProperty = BindingProperty, + DependencyObject = DependencyObject, + Value = Value, + _renewAction = _renewAction + }); + } + + /// <summary> + /// Generates a new <see cref="BindingEventContainer"/> for the specified Take element and binding property. + /// </summary> + /// <param name="dependencyObject">The take element.</param> + /// <param name="dependencyProperty">The binding property.</param> + /// <returns></returns> + public static BindingEventContainer Generate(DependencyObject dependencyObject, DependencyProperty dependencyProperty) + { + BindingEventContainer container = new BindingEventContainer(dependencyObject, new BindingProperty(dependencyProperty)); + + container._renewAction = () => + { + Binding binding = new Binding(); + binding.Mode = BindingMode.OneWay; + binding.Source = dependencyObject; + binding.Path = new PropertyPath(dependencyProperty); + BindingOperations.SetBinding(container, BindingEventContainer.ValueProperty, binding); + }; + + container._renewAction.Invoke(); + + return container; + } + } +} diff --git a/Software/Visual_Studio/Tango.SharedUI/Binding/BindingProperty.cs b/Software/Visual_Studio/Tango.SharedUI/Binding/BindingProperty.cs new file mode 100644 index 000000000..79d4f1c71 --- /dev/null +++ b/Software/Visual_Studio/Tango.SharedUI/Binding/BindingProperty.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; + +namespace Tango.SharedUI +{ + /// <summary> + /// Represents a binding property. + /// </summary> + public class BindingProperty + { + /// <summary> + /// Gets or sets the dependency property. + /// </summary> + public DependencyProperty DependencyProperty { get; set; } + + /// <summary> + /// Initializes a new instance of the <see cref="BindingProperty"/> class. + /// </summary> + public BindingProperty() + { + + } + + /// <summary> + /// Initializes a new instance of the <see cref="BindingProperty"/> class. + /// </summary> + /// <param name="dp">The dependency property.</param> + /// <param name="mode">The mode.</param> + public BindingProperty(DependencyProperty dp) : this() + { + DependencyProperty = dp; + } + } +} diff --git a/Software/Visual_Studio/Tango.SharedUI/Controls/NavigationControl.cs b/Software/Visual_Studio/Tango.SharedUI/Controls/NavigationControl.cs index 15d15decb..ce1fca7ac 100644 --- a/Software/Visual_Studio/Tango.SharedUI/Controls/NavigationControl.cs +++ b/Software/Visual_Studio/Tango.SharedUI/Controls/NavigationControl.cs @@ -22,7 +22,9 @@ namespace Tango.SharedUI.Controls public class NavigationControl : UserControl { private event Action NavigationCompleted; + public event EventHandler<FrameworkElement> SelectedElementChanged; private Thread _navigationThread; + private bool _preventSelectedObjectNavigation; private ProducerConsumerQueue<NavigationQueueItem> _navigationQueue; private class NavigationQueueItem @@ -191,14 +193,12 @@ namespace Tango.SharedUI.Controls get { return (object)GetValue(SelectedObjectProperty); } set { SetValue(SelectedObjectProperty, value); } } - - // Using a DependencyProperty as the backing store for SelectedObject. This enables animation, styling, binding, etc... public static readonly DependencyProperty SelectedObjectProperty = - DependencyProperty.Register("SelectedObject", typeof(object), typeof(NavigationControl), new PropertyMetadata(null, (d, e) => (d as NavigationControl).OnSelectedObjectChanged())); + DependencyProperty.Register("SelectedObject", typeof(object), typeof(NavigationControl), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, (d, e) => (d as NavigationControl).OnSelectedObjectChanged())); private void OnSelectedObjectChanged() { - if (SelectedObject != null) + if (SelectedObject != null && !_preventSelectedObjectNavigation) { NavigateTo(SelectedObject); } @@ -218,7 +218,7 @@ namespace Tango.SharedUI.Controls set { SetValue(SelectedElementProperty, value); } } public static readonly DependencyProperty SelectedElementProperty = - DependencyProperty.Register("SelectedElement", typeof(FrameworkElement), typeof(NavigationControl), new PropertyMetadata(null, (d, e) => (d as NavigationControl).OnSelectedElementChanged(e.OldValue as FrameworkElement, e.NewValue as FrameworkElement))); + DependencyProperty.Register("SelectedElement", typeof(FrameworkElement), typeof(NavigationControl), new FrameworkPropertyMetadata(null, (d, e) => (d as NavigationControl).OnSelectedElementChanged(e.OldValue as FrameworkElement, e.NewValue as FrameworkElement))); public TransitionTypes TransitionType { @@ -310,7 +310,9 @@ namespace Tango.SharedUI.Controls /// <returns></returns> public static String GetNavigationName(FrameworkElement element) { - return element.GetValue(NavigationName).ToStringSafe(); + var name = element.GetValue(NavigationName).ToStringSafe(); + if (String.IsNullOrEmpty(name)) name = element.GetType().Name; + return name; } #endregion @@ -383,6 +385,8 @@ namespace Tango.SharedUI.Controls } else { + Elements.ToList().ForEach(x => x.FocusVisualStyle = null); + var toRemove = _grid.Children.OfType<NavigationElement>().ToList().Where(x => !Elements.Contains(x.Element)).ToList(); var toAdd = Elements.Where(x => !_grid.Children.OfType<NavigationElement>().Select(y => y.Element).ToList().Contains(x)).ToList(); @@ -622,6 +626,14 @@ namespace Tango.SharedUI.Controls protected virtual void OnSelectedElementChanged(FrameworkElement fromElement, FrameworkElement toElement) { Navigate(GetElementContainer(fromElement), GetElementContainer(toElement)); + SelectedElementChanged?.Invoke(this, toElement); + + if (toElement != null) + { + _preventSelectedObjectNavigation = true; + SelectedObject = GetNavigationName(toElement); + _preventSelectedObjectNavigation = false; + } } #endregion @@ -696,7 +708,7 @@ namespace Tango.SharedUI.Controls FrameworkElement view = null; - view = NavigateTo(navigationName, () => + view = NavigateTo(navigationName, () => { source.SetResult(view); }); diff --git a/Software/Visual_Studio/Tango.SharedUI/Converters/StringToTitleCaseConverter.cs b/Software/Visual_Studio/Tango.SharedUI/Converters/StringToTitleCaseConverter.cs new file mode 100644 index 000000000..6bafd1fd0 --- /dev/null +++ b/Software/Visual_Studio/Tango.SharedUI/Converters/StringToTitleCaseConverter.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Data; + +namespace Tango.SharedUI.Converters +{ + public class StringToTitleCaseConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value != null) + { + return value.ToString().ToTitleCase(); + } + else + { + return value; + } + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/Software/Visual_Studio/Tango.SharedUI/Tango.SharedUI.csproj b/Software/Visual_Studio/Tango.SharedUI/Tango.SharedUI.csproj index 2170b6d58..834e9e1fe 100644 --- a/Software/Visual_Studio/Tango.SharedUI/Tango.SharedUI.csproj +++ b/Software/Visual_Studio/Tango.SharedUI/Tango.SharedUI.csproj @@ -64,6 +64,9 @@ <Compile Include="..\Versioning\GlobalVersionInfo.cs"> <Link>GlobalVersionInfo.cs</Link> </Compile> + <Compile Include="Binding\BindingEventArgs.cs" /> + <Compile Include="Binding\BindingEventContainer.cs" /> + <Compile Include="Binding\BindingProperty.cs" /> <Compile Include="Components\SelectedObject.cs" /> <Compile Include="Components\SelectedObjectCollection.cs" /> <Compile Include="Components\TextController.cs" /> @@ -133,6 +136,7 @@ <Compile Include="Converters\StringNullOrEmptyToBooleanConverter.cs" /> <Compile Include="Converters\StringToLinesConverter.cs" /> <Compile Include="Converters\StringToOneLineConverter.cs" /> + <Compile Include="Converters\StringToTitleCaseConverter.cs" /> <Compile Include="Converters\StringToWordsConverter.cs" /> <Compile Include="Converters\TimeSpanToMinutesConverter.cs" /> <Compile Include="Converters\TimeSpanToSecondsConverter.cs" /> |
