using System; using System.Collections.Generic; using System.Collections.ObjectModel; 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.Markup; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using Tango.SharedUI; using Tango.SharedUI.Controls; using static Tango.SharedUI.Controls.NavigationControl; namespace Tango.FSE.Common.Controls { [ContentProperty(nameof(Elements))] public class FSETabControl : Control { private NavigationControl _navigationControl; public ObservableCollection Elements { get { return (ObservableCollection)GetValue(ElementsProperty); } set { SetValue(ElementsProperty, value); } } public static readonly DependencyProperty ElementsProperty = DependencyProperty.Register("Elements", typeof(ObservableCollection), typeof(FSETabControl), new PropertyMetadata(null)); public FrameworkElement SelectedElement { get { return (FrameworkElement)GetValue(SelectedElementProperty); } set { SetValue(SelectedElementProperty, value); } } public static readonly DependencyProperty SelectedElementProperty = DependencyProperty.Register("SelectedElement", typeof(FrameworkElement), typeof(FSETabControl), new PropertyMetadata(null)); public TransitionTypes TransitionType { get { return (TransitionTypes)GetValue(TransitionTypeProperty); } set { SetValue(TransitionTypeProperty, value); } } public static readonly DependencyProperty TransitionTypeProperty = DependencyProperty.Register("TransitionType", typeof(TransitionTypes), typeof(FSETabControl), new PropertyMetadata(TransitionTypes.Slide)); public bool TransitionAlwaysFades { get { return (bool)GetValue(TransitionAlwaysFadesProperty); } set { SetValue(TransitionAlwaysFadesProperty, value); } } public static readonly DependencyProperty TransitionAlwaysFadesProperty = DependencyProperty.Register("TransitionAlwaysFades", typeof(bool), typeof(FSETabControl), new PropertyMetadata(false)); public Duration TransitionDuration { get { return (Duration)GetValue(TransitionDurationProperty); } set { SetValue(TransitionDurationProperty, value); } } public static readonly DependencyProperty TransitionDurationProperty = DependencyProperty.Register("TransitionDuration", typeof(Duration), typeof(FSETabControl), new PropertyMetadata(new Duration(TimeSpan.FromSeconds(0.2)))); public object SelectedObject { get { return (object)GetValue(SelectedObjectProperty); } set { SetValue(SelectedObjectProperty, value); } } public static readonly DependencyProperty SelectedObjectProperty = DependencyProperty.Register("SelectedObject", typeof(object), typeof(FSETabControl), new PropertyMetadata(null)); public double TabsWidth { get { return (double)GetValue(TabsWidthProperty); } set { SetValue(TabsWidthProperty, value); } } public static readonly DependencyProperty TabsWidthProperty = DependencyProperty.Register("TabsWidth", typeof(double), typeof(FSETabControl), new PropertyMetadata(double.NaN)); public FSETabControl() { Elements = new ObservableCollection(); } public override void OnApplyTemplate() { base.OnApplyTemplate(); _navigationControl = GetTemplateChild("navigation") as NavigationControl; _navigationControl.SelectedElementChanged += (x, e) => { SelectedElement = e; }; Elements = Elements.Where(x => !GetHidden(x)).ToObservableCollection(); _navigationControl.Elements = Elements; } static FSETabControl() { DefaultStyleKeyProperty.OverrideMetadata(typeof(FSETabControl), new FrameworkPropertyMetadata(typeof(FSETabControl))); } #region Attached Properties #region Hidden /// /// Determines the element navigation name. /// public static readonly DependencyProperty Hidden = DependencyProperty.RegisterAttached("Hidden", typeof(bool), typeof(FSETabControl), new FrameworkPropertyMetadata(false)); /// /// Sets the name of the navigation. /// /// The element. /// The value. public static void SetHidden(FrameworkElement element, bool value) { element.SetValue(Hidden, value); } /// /// Gets the name of the navigation. /// /// The element. /// public static bool GetHidden(FrameworkElement element) { return (bool)element.GetValue(Hidden); } #endregion #endregion } }