diff --git a/src/MahApps.Metro.Samples/MahApps.Metro.Demo/ExampleViews/HamburgerMenuCreatorsUpdate.xaml b/src/MahApps.Metro.Samples/MahApps.Metro.Demo/ExampleViews/HamburgerMenuCreatorsUpdate.xaml index 2f6164b9fb..5cb79f0668 100644 --- a/src/MahApps.Metro.Samples/MahApps.Metro.Demo/ExampleViews/HamburgerMenuCreatorsUpdate.xaml +++ b/src/MahApps.Metro.Samples/MahApps.Metro.Demo/ExampleViews/HamburgerMenuCreatorsUpdate.xaml @@ -162,7 +162,7 @@ - + diff --git a/src/MahApps.Metro.Samples/MahApps.Metro.Demo/ExampleViews/HamburgerMenuDefault.xaml b/src/MahApps.Metro.Samples/MahApps.Metro.Demo/ExampleViews/HamburgerMenuDefault.xaml index d08da9a9c7..f0bc159fb4 100644 --- a/src/MahApps.Metro.Samples/MahApps.Metro.Demo/ExampleViews/HamburgerMenuDefault.xaml +++ b/src/MahApps.Metro.Samples/MahApps.Metro.Demo/ExampleViews/HamburgerMenuDefault.xaml @@ -205,7 +205,10 @@ - + diff --git a/src/MahApps.Metro/Controls/HamburgerMenu/HamburgerMenu.EventArgs.cs b/src/MahApps.Metro/Controls/HamburgerMenu/HamburgerMenu.EventArgs.cs index 70e4821662..5766c621d9 100644 --- a/src/MahApps.Metro/Controls/HamburgerMenu/HamburgerMenu.EventArgs.cs +++ b/src/MahApps.Metro/Controls/HamburgerMenu/HamburgerMenu.EventArgs.cs @@ -3,7 +3,7 @@ namespace MahApps.Metro.Controls { /// - /// EventArgs used for the ItemClick and OptionsItemClick event. + /// EventArgs used for the and events. /// public class ItemClickEventArgs : RoutedEventArgs { @@ -25,18 +25,18 @@ public ItemClickEventArgs(RoutedEvent routedEvent, object source) } /// - /// Gets the clicked item + /// Gets the clicked item (options item). /// public object ClickedItem { get; internal set; } } /// - /// RoutedEventHandler used for the ItemClick and OptionsItemClick event. + /// RoutedEventHandler used for the and events. /// public delegate void ItemClickRoutedEventHandler(object sender, ItemClickEventArgs args); /// - /// EventArgs used for the ItemInvoked event. + /// EventArgs used for the event. /// public class HamburgerMenuItemInvokedEventArgs : RoutedEventArgs { @@ -58,7 +58,7 @@ public HamburgerMenuItemInvokedEventArgs(RoutedEvent routedEvent, object source) } /// - /// Gets the invoked item + /// Gets the invoked item. /// public object InvokedItem { get; internal set; } @@ -69,7 +69,7 @@ public HamburgerMenuItemInvokedEventArgs(RoutedEvent routedEvent, object source) } /// - /// RoutedEventHandler used for the ItemInvoked event. + /// RoutedEventHandler used for the event. /// public delegate void HamburgerMenuItemInvokedRoutedEventHandler(object sender, HamburgerMenuItemInvokedEventArgs args); } \ No newline at end of file diff --git a/src/MahApps.Metro/Controls/HamburgerMenu/HamburgerMenu.Events.cs b/src/MahApps.Metro/Controls/HamburgerMenu/HamburgerMenu.Events.cs index 65514d2f5f..32fa7cf92d 100644 --- a/src/MahApps.Metro/Controls/HamburgerMenu/HamburgerMenu.Events.cs +++ b/src/MahApps.Metro/Controls/HamburgerMenu/HamburgerMenu.Events.cs @@ -6,7 +6,11 @@ namespace MahApps.Metro.Controls public partial class HamburgerMenu { /// Identifies the routed event. - public static readonly RoutedEvent ItemClickEvent = EventManager.RegisterRoutedEvent("ItemClick", RoutingStrategy.Direct, typeof(ItemClickRoutedEventHandler), typeof(HamburgerMenu)); + public static readonly RoutedEvent ItemClickEvent + = EventManager.RegisterRoutedEvent(nameof(ItemClick), + RoutingStrategy.Direct, + typeof(ItemClickRoutedEventHandler), + typeof(HamburgerMenu)); /// /// Event raised when an item is clicked @@ -18,7 +22,11 @@ public event ItemClickRoutedEventHandler ItemClick } /// Identifies the routed event. - public static readonly RoutedEvent OptionsItemClickEvent = EventManager.RegisterRoutedEvent("OptionsItemClick", RoutingStrategy.Direct, typeof(ItemClickRoutedEventHandler), typeof(HamburgerMenu)); + public static readonly RoutedEvent OptionsItemClickEvent + = EventManager.RegisterRoutedEvent(nameof(OptionsItemClick), + RoutingStrategy.Direct, + typeof(ItemClickRoutedEventHandler), + typeof(HamburgerMenu)); /// /// Event raised when an options' item is clicked @@ -30,7 +38,11 @@ public event ItemClickRoutedEventHandler OptionsItemClick } /// Identifies the routed event. - public static readonly RoutedEvent ItemInvokedEvent = EventManager.RegisterRoutedEvent("ItemInvoked", RoutingStrategy.Direct, typeof(HamburgerMenuItemInvokedRoutedEventHandler), typeof(HamburgerMenu)); + public static readonly RoutedEvent ItemInvokedEvent + = EventManager.RegisterRoutedEvent(nameof(ItemInvoked), + RoutingStrategy.Direct, + typeof(HamburgerMenuItemInvokedRoutedEventHandler), + typeof(HamburgerMenu)); /// /// Event raised when an item is invoked @@ -42,7 +54,11 @@ public event HamburgerMenuItemInvokedRoutedEventHandler ItemInvoked } /// Identifies the routed event. - public static readonly RoutedEvent HamburgerButtonClickEvent = EventManager.RegisterRoutedEvent("HamburgerButtonClick", RoutingStrategy.Direct, typeof(RoutedEventHandler), typeof(HamburgerMenu)); + public static readonly RoutedEvent HamburgerButtonClickEvent + = EventManager.RegisterRoutedEvent(nameof(HamburgerButtonClick), + RoutingStrategy.Direct, + typeof(RoutedEventHandler), + typeof(HamburgerMenu)); /// /// Event raised when the hamburger button is clicked @@ -185,8 +201,7 @@ private bool RaiseOptionsItemEvents(object selectedItem) private void ButtonsListView_SelectionChanged(object sender, SelectionChangedEventArgs e) { - var listBox = sender as ListBox; - if (listBox == null) + if (!(sender is ListBox listBox)) { return; } @@ -216,8 +231,7 @@ private void ButtonsListView_SelectionChanged(object sender, SelectionChangedEve private void OptionsListView_SelectionChanged(object sender, SelectionChangedEventArgs e) { - var listBox = sender as ListBox; - if (listBox == null) + if (!(sender is ListBox listBox)) { return; } diff --git a/src/MahApps.Metro/Controls/HamburgerMenu/HamburgerMenu.HamburgerButton.cs b/src/MahApps.Metro/Controls/HamburgerMenu/HamburgerMenu.HamburgerButton.cs index aa1fb5014a..6ec1a92606 100644 --- a/src/MahApps.Metro/Controls/HamburgerMenu/HamburgerMenu.HamburgerButton.cs +++ b/src/MahApps.Metro/Controls/HamburgerMenu/HamburgerMenu.HamburgerButton.cs @@ -1,4 +1,5 @@ using System.Windows; +using System.Windows.Automation; using System.Windows.Controls; namespace MahApps.Metro.Controls @@ -7,25 +8,78 @@ namespace MahApps.Metro.Controls public partial class HamburgerMenu { /// Identifies the dependency property. - public static readonly DependencyProperty HamburgerWidthProperty = DependencyProperty.Register(nameof(HamburgerWidth), typeof(double), typeof(HamburgerMenu), new PropertyMetadata(48.0)); + public static readonly DependencyProperty HamburgerWidthProperty + = DependencyProperty.Register(nameof(HamburgerWidth), + typeof(double), + typeof(HamburgerMenu), + new PropertyMetadata(48.0)); + + /// + /// Gets or sets HamburgerMenu button's . + /// + public double HamburgerWidth + { + get => (double)this.GetValue(HamburgerWidthProperty); + set => this.SetValue(HamburgerWidthProperty, value); + } /// Identifies the dependency property. - public static readonly DependencyProperty HamburgerHeightProperty = DependencyProperty.Register(nameof(HamburgerHeight), typeof(double), typeof(HamburgerMenu), new PropertyMetadata(48.0)); + public static readonly DependencyProperty HamburgerHeightProperty + = DependencyProperty.Register(nameof(HamburgerHeight), + typeof(double), + typeof(HamburgerMenu), + new PropertyMetadata(48.0)); + + /// + /// Gets or sets the for the HamburgerMenu button. + /// + public double HamburgerHeight + { + get => (double)this.GetValue(HamburgerHeightProperty); + set => this.SetValue(HamburgerHeightProperty, value); + } /// Identifies the dependency property. - public static readonly DependencyProperty HamburgerMarginProperty = DependencyProperty.Register(nameof(HamburgerMargin), typeof(Thickness), typeof(HamburgerMenu), new PropertyMetadata(null)); + public static readonly DependencyProperty HamburgerMarginProperty + = DependencyProperty.Register(nameof(HamburgerMargin), + typeof(Thickness), + typeof(HamburgerMenu), + new PropertyMetadata(new Thickness())); + + /// + /// Gets or sets the margin for the HamburgerMenu button. + /// + public Thickness HamburgerMargin + { + get => (Thickness)this.GetValue(HamburgerMarginProperty); + set => this.SetValue(HamburgerMarginProperty, value); + } /// Identifies the dependency property. - public static readonly DependencyProperty HamburgerVisibilityProperty = DependencyProperty.Register(nameof(HamburgerVisibility), typeof(Visibility), typeof(HamburgerMenu), new PropertyMetadata(Visibility.Visible)); + public static readonly DependencyProperty HamburgerVisibilityProperty + = DependencyProperty.Register(nameof(HamburgerVisibility), + typeof(Visibility), + typeof(HamburgerMenu), + new PropertyMetadata(Visibility.Visible)); - /// Identifies the dependency property. - public static readonly DependencyProperty HamburgerButtonStyleProperty = DependencyProperty.Register(nameof(HamburgerButtonStyle), typeof(Style), typeof(HamburgerMenu), new PropertyMetadata(null)); + /// + /// Gets or sets the for the HamburgerMenu button. + /// + public Visibility HamburgerVisibility + { + get => (Visibility)this.GetValue(HamburgerVisibilityProperty); + set => this.SetValue(HamburgerVisibilityProperty, value); + } - /// Identifies the dependency property. - public static readonly DependencyProperty HamburgerButtonTemplateProperty = DependencyProperty.Register(nameof(HamburgerButtonTemplate), typeof(DataTemplate), typeof(HamburgerMenu), new PropertyMetadata(null)); + /// Identifies the dependency property. + public static readonly DependencyProperty HamburgerButtonStyleProperty + = DependencyProperty.Register(nameof(HamburgerButtonStyle), + typeof(Style), + typeof(HamburgerMenu), + new PropertyMetadata(null)); /// - /// Gets or sets the Style used for the hamburger button. + /// Gets or sets the for the HamburgerMenu button. /// public Style HamburgerButtonStyle { @@ -33,8 +87,15 @@ public Style HamburgerButtonStyle set => this.SetValue(HamburgerButtonStyleProperty, value); } + /// Identifies the dependency property. + public static readonly DependencyProperty HamburgerButtonTemplateProperty + = DependencyProperty.Register(nameof(HamburgerButtonTemplate), + typeof(DataTemplate), + typeof(HamburgerMenu), + new PropertyMetadata(null)); + /// - /// Gets or sets a template for the hamburger button. + /// Gets or sets the for the HamburgerMenu button. /// public DataTemplate HamburgerButtonTemplate { @@ -42,52 +103,59 @@ public DataTemplate HamburgerButtonTemplate set => this.SetValue(HamburgerButtonTemplateProperty, value); } - /// Identifies the dependency property. - public static readonly DependencyProperty HamburgerMenuHeaderTemplateProperty = DependencyProperty.Register(nameof(HamburgerMenuHeaderTemplate), typeof(DataTemplate), typeof(HamburgerMenu), new PropertyMetadata(null)); + /// Identifies the dependency property. + public static readonly DependencyProperty HamburgerButtonNameProperty + = DependencyProperty.Register(nameof(HamburgerButtonName), + typeof(string), + typeof(HamburgerMenu), + new UIPropertyMetadata(string.Empty), + new ValidateValueCallback(IsNotNull)); /// - /// Gets or sets a template for the hamburger pane header. + /// Gets or sets the for the HamburgerMenu button. /// - public DataTemplate HamburgerMenuHeaderTemplate + public string HamburgerButtonName { - get => (DataTemplate)this.GetValue(HamburgerMenuHeaderTemplateProperty); - set => this.SetValue(HamburgerMenuHeaderTemplateProperty, value); + get => (string)this.GetValue(HamburgerButtonNameProperty); + set => this.SetValue(HamburgerButtonNameProperty, value); } - /// - /// Gets or sets main button's width. - /// - public double HamburgerWidth - { - get => (double)this.GetValue(HamburgerWidthProperty); - set => this.SetValue(HamburgerWidthProperty, value); - } + /// Identifies the dependency property. + public static readonly DependencyProperty HamburgerButtonHelpTextProperty + = DependencyProperty.Register(nameof(HamburgerButtonHelpText), + typeof(string), + typeof(HamburgerMenu), + new UIPropertyMetadata(string.Empty), + new ValidateValueCallback(IsNotNull)); /// - /// Gets or sets main button's height. + /// Gets or sets the for the HamburgerMenu button. /// - public double HamburgerHeight + public string HamburgerButtonHelpText { - get => (double)this.GetValue(HamburgerHeightProperty); - set => this.SetValue(HamburgerHeightProperty, value); + get => (string)this.GetValue(HamburgerButtonHelpTextProperty); + set => this.SetValue(HamburgerButtonHelpTextProperty, value); } + /// Identifies the dependency property. + public static readonly DependencyProperty HamburgerMenuHeaderTemplateProperty + = DependencyProperty.Register(nameof(HamburgerMenuHeaderTemplate), + typeof(DataTemplate), + typeof(HamburgerMenu), + new PropertyMetadata(null)); + /// - /// Gets or sets main button's margin. + /// Gets or sets the for the HamburgerMenu pane header. /// - public Thickness HamburgerMargin + public DataTemplate HamburgerMenuHeaderTemplate { - get => (Thickness)this.GetValue(HamburgerMarginProperty); - set => this.SetValue(HamburgerMarginProperty, value); + get => (DataTemplate)this.GetValue(HamburgerMenuHeaderTemplateProperty); + set => this.SetValue(HamburgerMenuHeaderTemplateProperty, value); } - /// - /// Gets or sets main button's visibility. - /// - public Visibility HamburgerVisibility + private static bool IsNotNull(object value) { - get => (Visibility)this.GetValue(HamburgerVisibilityProperty); - set => this.SetValue(HamburgerVisibilityProperty, value); + return value != null; } } } \ No newline at end of file diff --git a/src/MahApps.Metro/Controls/HamburgerMenu/HamburgerMenu.Options.cs b/src/MahApps.Metro/Controls/HamburgerMenu/HamburgerMenu.Options.cs index f6699538cd..1945c5135b 100644 --- a/src/MahApps.Metro/Controls/HamburgerMenu/HamburgerMenu.Options.cs +++ b/src/MahApps.Metro/Controls/HamburgerMenu/HamburgerMenu.Options.cs @@ -5,34 +5,15 @@ namespace MahApps.Metro.Controls { + [StyleTypedProperty(Property = nameof(OptionsItemContainerStyle), StyleTargetType = typeof(ListBoxItem))] public partial class HamburgerMenu { /// Identifies the dependency property. - public static readonly DependencyProperty OptionsItemsSourceProperty = DependencyProperty.Register(nameof(OptionsItemsSource), typeof(object), typeof(HamburgerMenu), new PropertyMetadata(null)); - - /// Identifies the dependency property. - public static readonly DependencyProperty OptionsItemContainerStyleProperty = DependencyProperty.Register(nameof(OptionsItemContainerStyle), typeof(Style), typeof(HamburgerMenu), new PropertyMetadata(null)); - - /// Identifies the dependency property. - public static readonly DependencyProperty OptionsItemTemplateProperty = DependencyProperty.Register(nameof(OptionsItemTemplate), typeof(DataTemplate), typeof(HamburgerMenu), new PropertyMetadata(null)); - - /// Identifies the dependency property. - public static readonly DependencyProperty OptionsItemTemplateSelectorProperty = DependencyProperty.Register(nameof(OptionsItemTemplateSelector), typeof(DataTemplateSelector), typeof(HamburgerMenu), new PropertyMetadata(null)); - - /// Identifies the dependency property. - public static readonly DependencyProperty OptionsVisibilityProperty = DependencyProperty.Register(nameof(OptionsVisibility), typeof(Visibility), typeof(HamburgerMenu), new PropertyMetadata(Visibility.Visible)); - - /// Identifies the dependency property. - public static readonly DependencyProperty SelectedOptionsItemProperty = DependencyProperty.Register(nameof(SelectedOptionsItem), typeof(object), typeof(HamburgerMenu), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault)); - - /// Identifies the dependency property. - public static readonly DependencyProperty SelectedOptionsIndexProperty = DependencyProperty.Register(nameof(SelectedOptionsIndex), typeof(int), typeof(HamburgerMenu), new FrameworkPropertyMetadata(-1, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault | FrameworkPropertyMetadataOptions.Journal)); - - /// Identifies the dependency property. - public static readonly DependencyProperty OptionsItemCommandProperty = DependencyProperty.Register(nameof(OptionsItemCommand), typeof(ICommand), typeof(HamburgerMenu), new PropertyMetadata(null)); - - /// Identifies the dependency property. - public static readonly DependencyProperty OptionsItemCommandParameterProperty = DependencyProperty.Register(nameof(OptionsItemCommandParameter), typeof(object), typeof(HamburgerMenu), new PropertyMetadata(null)); + public static readonly DependencyProperty OptionsItemsSourceProperty + = DependencyProperty.Register(nameof(OptionsItemsSource), + typeof(object), + typeof(HamburgerMenu), + new PropertyMetadata(null)); /// /// Gets or sets an object source used to generate the content of the options. @@ -43,8 +24,15 @@ public object OptionsItemsSource set => this.SetValue(OptionsItemsSourceProperty, value); } + /// Identifies the dependency property. + public static readonly DependencyProperty OptionsItemContainerStyleProperty + = DependencyProperty.Register(nameof(OptionsItemContainerStyle), + typeof(Style), + typeof(HamburgerMenu), + new PropertyMetadata(null)); + /// - /// Gets or sets the Style used for each item in the options. + /// Gets or sets the used for each item in the options. /// public Style OptionsItemContainerStyle { @@ -52,8 +40,15 @@ public Style OptionsItemContainerStyle set => this.SetValue(OptionsItemContainerStyleProperty, value); } + /// Identifies the dependency property. + public static readonly DependencyProperty OptionsItemTemplateProperty + = DependencyProperty.Register(nameof(OptionsItemTemplate), + typeof(DataTemplate), + typeof(HamburgerMenu), + new PropertyMetadata(null)); + /// - /// Gets or sets the DataTemplate used to display each item in the options. + /// Gets or sets the used to display each item in the options. /// public DataTemplate OptionsItemTemplate { @@ -61,8 +56,15 @@ public DataTemplate OptionsItemTemplate set => this.SetValue(OptionsItemTemplateProperty, value); } + /// Identifies the dependency property. + public static readonly DependencyProperty OptionsItemTemplateSelectorProperty + = DependencyProperty.Register(nameof(OptionsItemTemplateSelector), + typeof(DataTemplateSelector), + typeof(HamburgerMenu), + new PropertyMetadata(null)); + /// - /// Gets or sets the DataTemplateSelector used to display each item in the options. + /// Gets or sets the used to display each item in the options. /// public DataTemplateSelector OptionsItemTemplateSelector { @@ -70,27 +72,15 @@ public DataTemplateSelector OptionsItemTemplateSelector set => this.SetValue(OptionsItemTemplateSelectorProperty, value); } - /// - /// Gets the collection used to generate the content of the option list. - /// - /// - /// Exception thrown if OptionsListView is not yet defined. - /// - public ItemCollection OptionsItems - { - get - { - if (this.optionsListView == null) - { - throw new Exception("OptionsListView is not defined yet. Please use OptionsItemsSource instead."); - } - - return this.optionsListView?.Items; - } - } + /// Identifies the dependency property. + public static readonly DependencyProperty OptionsVisibilityProperty + = DependencyProperty.Register(nameof(OptionsVisibility), + typeof(Visibility), + typeof(HamburgerMenu), + new PropertyMetadata(Visibility.Visible)); /// - /// Gets or sets the visibility of the options menu. + /// Gets or sets the of the options menu. /// public Visibility OptionsVisibility { @@ -98,6 +88,13 @@ public Visibility OptionsVisibility set => this.SetValue(OptionsVisibilityProperty, value); } + /// Identifies the dependency property. + public static readonly DependencyProperty SelectedOptionsItemProperty + = DependencyProperty.Register(nameof(SelectedOptionsItem), + typeof(object), + typeof(HamburgerMenu), + new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault)); + /// /// Gets or sets the selected options menu item. /// @@ -107,6 +104,13 @@ public object SelectedOptionsItem set => this.SetValue(SelectedOptionsItemProperty, value); } + /// Identifies the dependency property. + public static readonly DependencyProperty SelectedOptionsIndexProperty + = DependencyProperty.Register(nameof(SelectedOptionsIndex), + typeof(int), + typeof(HamburgerMenu), + new FrameworkPropertyMetadata(-1, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault | FrameworkPropertyMetadataOptions.Journal)); + /// /// Gets or sets the selected options menu index. /// @@ -116,8 +120,15 @@ public int SelectedOptionsIndex set => this.SetValue(SelectedOptionsIndexProperty, value); } + /// Identifies the dependency property. + public static readonly DependencyProperty OptionsItemCommandProperty + = DependencyProperty.Register(nameof(OptionsItemCommand), + typeof(ICommand), + typeof(HamburgerMenu), + new PropertyMetadata(null)); + /// - /// Gets or sets a command which will be executed if an options item is clicked by the user. + /// Gets or sets a which will be executed if an options item was clicked by the user. /// public ICommand OptionsItemCommand { @@ -125,8 +136,15 @@ public ICommand OptionsItemCommand set => this.SetValue(OptionsItemCommandProperty, value); } + /// Identifies the dependency property. + public static readonly DependencyProperty OptionsItemCommandParameterProperty + = DependencyProperty.Register(nameof(OptionsItemCommandParameter), + typeof(object), + typeof(HamburgerMenu), + new PropertyMetadata(null)); + /// - /// Gets or sets the command parameter which will be passed by the OptionsItemCommand. + /// Gets or sets the parameter which will be passed by the . /// public object OptionsItemCommandParameter { @@ -135,7 +153,26 @@ public object OptionsItemCommandParameter } /// - /// Executes the options item command which can be set by the user. + /// Gets the collection used to generate the content of the option list. + /// + /// + /// Exception thrown if OptionsListView is not yet defined. + /// + public ItemCollection OptionsItems + { + get + { + if (this.optionsListView == null) + { + throw new Exception("OptionsListView is not defined yet. Please use OptionsItemsSource instead."); + } + + return this.optionsListView.Items; + } + } + + /// + /// Executes the . /// public void RaiseOptionsItemCommand() { diff --git a/src/MahApps.Metro/Controls/HamburgerMenu/HamburgerMenu.Properties.cs b/src/MahApps.Metro/Controls/HamburgerMenu/HamburgerMenu.Properties.cs index 3d35a4f001..b4ec1ce17a 100644 --- a/src/MahApps.Metro/Controls/HamburgerMenu/HamburgerMenu.Properties.cs +++ b/src/MahApps.Metro/Controls/HamburgerMenu/HamburgerMenu.Properties.cs @@ -7,12 +7,20 @@ namespace MahApps.Metro.Controls { [StyleTypedProperty(Property = nameof(ResizeThumbStyle), StyleTargetType = typeof(MetroThumb))] + [StyleTypedProperty(Property = nameof(ItemContainerStyle), StyleTargetType = typeof(ListBoxItem))] + [StyleTypedProperty(Property = nameof(HeaderItemContainerStyle), StyleTargetType = typeof(ListBoxItem))] + [StyleTypedProperty(Property = nameof(SeparatorItemContainerStyle), StyleTargetType = typeof(ListBoxItem))] + [StyleTypedProperty(Property = nameof(ItemFocusVisualStyle), StyleTargetType = typeof(Control))] public partial class HamburgerMenu { private ControlTemplate _defaultItemFocusVisualTemplate = null; /// Identifies the dependency property. - public static readonly DependencyProperty OpenPaneLengthProperty = DependencyProperty.Register(nameof(OpenPaneLength), typeof(double), typeof(HamburgerMenu), new PropertyMetadata(240.0, OpenPaneLengthPropertyChangedCallback, OnOpenPaneLengthCoerceValueCallback)); + public static readonly DependencyProperty OpenPaneLengthProperty + = DependencyProperty.Register(nameof(OpenPaneLength), + typeof(double), + typeof(HamburgerMenu), + new PropertyMetadata(240.0, OpenPaneLengthPropertyChangedCallback, OnOpenPaneLengthCoerceValueCallback)); private static object OnOpenPaneLengthCoerceValueCallback(DependencyObject dependencyObject, object inputValue) { @@ -64,8 +72,45 @@ private static void OpenPaneLengthPropertyChangedCallback(DependencyObject depen } } + /// + /// Gets or sets the width of the pane when it's fully expanded. + /// + public double OpenPaneLength + { + get => (double)this.GetValue(OpenPaneLengthProperty); + set => this.SetValue(OpenPaneLengthProperty, value); + } + + /// Identifies the dependency property. + public static readonly DependencyProperty CompactPaneLengthProperty + = DependencyProperty.Register(nameof(CompactPaneLength), + typeof(double), typeof(HamburgerMenu), + new PropertyMetadata(48.0, OnCompactPaneLengthPropertyChangedCallback)); + + private static void OnCompactPaneLengthPropertyChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e) + { + if (e.OldValue != e.NewValue && e.NewValue is double && dependencyObject is HamburgerMenu hamburgerMenu) + { + hamburgerMenu.CoerceValue(OpenPaneLengthProperty); + hamburgerMenu.ChangeItemFocusVisualStyle(); + } + } + + /// + /// Gets or sets the width of the pane when in its compact display mode. + /// + public double CompactPaneLength + { + get => (double)this.GetValue(CompactPaneLengthProperty); + set => this.SetValue(CompactPaneLengthProperty, value); + } + /// Identifies the dependency property. - public static readonly DependencyProperty MinimumOpenPaneLengthProperty = DependencyProperty.Register(nameof(MinimumOpenPaneLength), typeof(double), typeof(HamburgerMenu), new PropertyMetadata(100d, MinimumOpenPaneLengthPropertyChangedCallback)); + public static readonly DependencyProperty MinimumOpenPaneLengthProperty + = DependencyProperty.Register(nameof(MinimumOpenPaneLength), + typeof(double), + typeof(HamburgerMenu), + new PropertyMetadata(100d, MinimumOpenPaneLengthPropertyChangedCallback)); private static void MinimumOpenPaneLengthPropertyChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e) { @@ -77,12 +122,8 @@ private static void MinimumOpenPaneLengthPropertyChangedCallback(DependencyObjec } /// - /// Gets or sets the minimum width of the pane when it's fully expanded. + /// Gets or sets the minimum width of the pane when it's fully expanded. /// - /// - /// The minimum width of the pane when it's fully expanded. The default is 320 device-independent - /// pixel (DIP). - /// public double MinimumOpenPaneLength { get => (double)this.GetValue(MinimumOpenPaneLengthProperty); @@ -90,7 +131,11 @@ public double MinimumOpenPaneLength } /// Identifies the dependency property. - public static readonly DependencyProperty MaximumOpenPaneLengthProperty = DependencyProperty.Register(nameof(MaximumOpenPaneLength), typeof(double), typeof(HamburgerMenu), new PropertyMetadata(500d, OnMaximumOpenPaneLengthPropertyChangedCallback)); + public static readonly DependencyProperty MaximumOpenPaneLengthProperty + = DependencyProperty.Register(nameof(MaximumOpenPaneLength), + typeof(double), + typeof(HamburgerMenu), + new PropertyMetadata(500d, OnMaximumOpenPaneLengthPropertyChangedCallback)); private static void OnMaximumOpenPaneLengthPropertyChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e) { @@ -102,12 +147,8 @@ private static void OnMaximumOpenPaneLengthPropertyChangedCallback(DependencyObj } /// - /// Gets or sets the maximum width of the pane when it's fully expanded. + /// Gets or sets the maximum width of the pane when it's fully expanded. /// - /// - /// The maximum width of the pane when it's fully expanded. The default is 320 device-independent - /// pixel (DIP). - /// public double MaximumOpenPaneLength { get => (double)this.GetValue(MaximumOpenPaneLengthProperty); @@ -115,7 +156,11 @@ public double MaximumOpenPaneLength } /// Identifies the dependency property. - public static readonly DependencyProperty CanResizeOpenPaneProperty = DependencyProperty.Register(nameof(CanResizeOpenPane), typeof(bool), typeof(HamburgerMenu), new PropertyMetadata(false, OnCanResizeOpenPanePropertyChangedCallback)); + public static readonly DependencyProperty CanResizeOpenPaneProperty + = DependencyProperty.Register(nameof(CanResizeOpenPane), + typeof(bool), + typeof(HamburgerMenu), + new PropertyMetadata(false, OnCanResizeOpenPanePropertyChangedCallback)); private static void OnCanResizeOpenPanePropertyChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e) { @@ -126,7 +171,7 @@ private static void OnCanResizeOpenPanePropertyChangedCallback(DependencyObject } /// - /// Gets or Sets if the open pane can be resized by the user. The default value is false. + /// Gets or Sets whether the open pane can be resized by the user. The default value is false. /// public bool CanResizeOpenPane { @@ -135,7 +180,11 @@ public bool CanResizeOpenPane } /// Identifies the dependency property. - public static readonly DependencyProperty ResizeThumbStyleProperty = DependencyProperty.Register(nameof(ResizeThumbStyle), typeof(Style), typeof(HamburgerMenu), new PropertyMetadata(null)); + public static readonly DependencyProperty ResizeThumbStyleProperty + = DependencyProperty.Register(nameof(ResizeThumbStyle), + typeof(Style), + typeof(HamburgerMenu), + new PropertyMetadata(null)); /// /// Gets or Sets the for the resizing Thumb (type of ) @@ -147,117 +196,36 @@ public Style ResizeThumbStyle } /// Identifies the dependency property. - public static readonly DependencyProperty PanePlacementProperty = DependencyProperty.Register(nameof(PanePlacement), typeof(SplitViewPanePlacement), typeof(HamburgerMenu), new PropertyMetadata(SplitViewPanePlacement.Left)); - - /// Identifies the dependency property. - public static readonly DependencyProperty DisplayModeProperty = DependencyProperty.Register(nameof(DisplayMode), typeof(SplitViewDisplayMode), typeof(HamburgerMenu), new PropertyMetadata(SplitViewDisplayMode.CompactInline, OnDisplayModePropertyChangedCallback)); + public static readonly DependencyProperty PanePlacementProperty + = DependencyProperty.Register(nameof(PanePlacement), + typeof(SplitViewPanePlacement), + typeof(HamburgerMenu), + new PropertyMetadata(SplitViewPanePlacement.Left)); - private static void OnDisplayModePropertyChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e) + /// + /// Gets or sets a value that specifies whether the pane is shown on the right or on left side of the HamburgerMenu. + /// + public SplitViewPanePlacement PanePlacement { - if (e.OldValue != e.NewValue && e.NewValue is SplitViewDisplayMode && dependencyObject is HamburgerMenu hamburgerMenu) - { - hamburgerMenu.CoerceValue(OpenPaneLengthProperty); - } + get => (SplitViewPanePlacement)this.GetValue(PanePlacementProperty); + set => this.SetValue(PanePlacementProperty, value); } - /// Identifies the dependency property. - public static readonly DependencyProperty CompactPaneLengthProperty = DependencyProperty.Register(nameof(CompactPaneLength), typeof(double), typeof(HamburgerMenu), new PropertyMetadata(48.0, OnCompactPaneLengthPropertyChangedCallback)); + /// Identifies the dependency property. + public static readonly DependencyProperty DisplayModeProperty + = DependencyProperty.Register(nameof(DisplayMode), + typeof(SplitViewDisplayMode), + typeof(HamburgerMenu), + new PropertyMetadata(SplitViewDisplayMode.CompactInline, OnDisplayModePropertyChangedCallback)); - private static void OnCompactPaneLengthPropertyChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e) + private static void OnDisplayModePropertyChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e) { - if (e.OldValue != e.NewValue && e.NewValue is double && dependencyObject is HamburgerMenu hamburgerMenu) + if (e.OldValue != e.NewValue && e.NewValue is SplitViewDisplayMode && dependencyObject is HamburgerMenu hamburgerMenu) { hamburgerMenu.CoerceValue(OpenPaneLengthProperty); - hamburgerMenu.ChangeItemFocusVisualStyle(); } } - /// Identifies the dependency property. - public static readonly DependencyProperty PaneMarginProperty = DependencyProperty.Register(nameof(PaneMargin), typeof(Thickness), typeof(HamburgerMenu), new PropertyMetadata(null)); - - /// Identifies the dependency property. - public static readonly DependencyProperty PaneHeaderMarginProperty = DependencyProperty.Register(nameof(PaneHeaderMargin), typeof(Thickness), typeof(HamburgerMenu), new PropertyMetadata(null)); - - /// Identifies the dependency property. - public static readonly DependencyProperty PaneBackgroundProperty = DependencyProperty.Register(nameof(PaneBackground), typeof(Brush), typeof(HamburgerMenu), new PropertyMetadata(null)); - - /// Identifies the dependency property. - public static readonly DependencyProperty PaneForegroundProperty = DependencyProperty.Register(nameof(PaneForeground), typeof(Brush), typeof(HamburgerMenu), new PropertyMetadata(null)); - - /// Identifies the dependency property. - public static readonly DependencyProperty IsPaneOpenProperty = DependencyProperty.Register(nameof(IsPaneOpen), typeof(bool), typeof(HamburgerMenu), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, IsPaneOpenPropertyChangedCallback)); - - private static void IsPaneOpenPropertyChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs args) - { - if (args.NewValue != args.OldValue) - { - (dependencyObject as HamburgerMenu)?.ChangeItemFocusVisualStyle(); - } - } - - /// Identifies the dependency property. - public static readonly DependencyProperty ItemsSourceProperty = DependencyProperty.Register(nameof(ItemsSource), typeof(object), typeof(HamburgerMenu), new PropertyMetadata(null)); - - /// Identifies the dependency property. - public static readonly DependencyProperty ItemContainerStyleProperty = DependencyProperty.Register(nameof(ItemContainerStyle), typeof(Style), typeof(HamburgerMenu), new PropertyMetadata(null)); - - /// Identifies the dependency property. - public static readonly DependencyProperty HeaderItemContainerStyleProperty = DependencyProperty.Register(nameof(HeaderItemContainerStyle), typeof(Style), typeof(HamburgerMenu), new PropertyMetadata(null)); - - /// Identifies the dependency property. - public static readonly DependencyProperty SeparatorItemContainerStyleProperty = DependencyProperty.Register(nameof(SeparatorItemContainerStyle), typeof(Style), typeof(HamburgerMenu), new PropertyMetadata(null)); - - /// Identifies the dependency property. - public static readonly DependencyProperty ItemTemplateProperty = DependencyProperty.Register(nameof(ItemTemplate), typeof(DataTemplate), typeof(HamburgerMenu), new PropertyMetadata(null)); - - /// Identifies the dependency property. - public static readonly DependencyProperty ItemTemplateSelectorProperty = DependencyProperty.Register(nameof(ItemTemplateSelector), typeof(DataTemplateSelector), typeof(HamburgerMenu), new PropertyMetadata(null)); - - /// Identifies the dependency property. - public static readonly DependencyProperty SelectedItemProperty = DependencyProperty.Register(nameof(SelectedItem), typeof(object), typeof(HamburgerMenu), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault)); - - /// Identifies the dependency property. - public static readonly DependencyProperty SelectedIndexProperty = DependencyProperty.Register(nameof(SelectedIndex), typeof(int), typeof(HamburgerMenu), new FrameworkPropertyMetadata(-1, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault | FrameworkPropertyMetadataOptions.Journal)); - - /// Identifies the dependency property. - public static readonly DependencyProperty ContentTransitionProperty = DependencyProperty.Register(nameof(ContentTransition), typeof(TransitionType), typeof(HamburgerMenu), new FrameworkPropertyMetadata(TransitionType.Normal)); - - /// Identifies the dependency property. - public static readonly DependencyProperty ItemCommandProperty = DependencyProperty.Register(nameof(ItemCommand), typeof(ICommand), typeof(HamburgerMenu), new PropertyMetadata(null)); - - /// Identifies the dependency property. - public static readonly DependencyProperty ItemCommandParameterProperty = DependencyProperty.Register(nameof(ItemCommandParameter), typeof(object), typeof(HamburgerMenu), new PropertyMetadata(null)); - - /// Identifies the dependency property. - public static readonly DependencyProperty VerticalScrollBarOnLeftSideProperty = DependencyProperty.Register(nameof(VerticalScrollBarOnLeftSide), typeof(bool), typeof(HamburgerMenu), new PropertyMetadata(false)); - - /// Identifies the dependency property. - public static readonly DependencyProperty ShowSelectionIndicatorProperty = DependencyProperty.Register(nameof(ShowSelectionIndicator), typeof(bool), typeof(HamburgerMenu), new PropertyMetadata(false)); - - /// Identifies the dependency property. - public static readonly DependencyPropertyKey ItemFocusVisualStylePropertyKey = DependencyProperty.RegisterReadOnly(nameof(ItemFocusVisualStyle), typeof(Style), typeof(HamburgerMenu), new PropertyMetadata(null)); - - /// Identifies the dependency property. - public static readonly DependencyProperty ItemFocusVisualStyleProperty = ItemFocusVisualStylePropertyKey.DependencyProperty; - - /// - /// Gets or sets the width of the pane when it's fully expanded. - /// - public double OpenPaneLength - { - get => (double)this.GetValue(OpenPaneLengthProperty); - set => this.SetValue(OpenPaneLengthProperty, value); - } - - /// - /// Gets or sets a value that specifies whether the pane is shown on the right or left side of the control. - /// - public SplitViewPanePlacement PanePlacement - { - get => (SplitViewPanePlacement)this.GetValue(PanePlacementProperty); - set => this.SetValue(PanePlacementProperty, value); - } - /// /// Gets or sets a value that specifies how the pane and content areas are shown. /// @@ -267,17 +235,15 @@ public SplitViewDisplayMode DisplayMode set => this.SetValue(DisplayModeProperty, value); } - /// - /// Gets or sets the width of the pane in its compact display mode. - /// - public double CompactPaneLength - { - get => (double)this.GetValue(CompactPaneLengthProperty); - set => this.SetValue(CompactPaneLengthProperty, value); - } + /// Identifies the dependency property. + public static readonly DependencyProperty PaneMarginProperty + = DependencyProperty.Register(nameof(PaneMargin), + typeof(Thickness), + typeof(HamburgerMenu), + new PropertyMetadata(new Thickness())); /// - /// Gets or sets the margin for the pane. + /// Gets or sets the margin for the pane. /// public Thickness PaneMargin { @@ -285,6 +251,13 @@ public Thickness PaneMargin set => this.SetValue(PaneMarginProperty, value); } + /// Identifies the dependency property. + public static readonly DependencyProperty PaneHeaderMarginProperty + = DependencyProperty.Register(nameof(PaneHeaderMargin), + typeof(Thickness), + typeof(HamburgerMenu), + new PropertyMetadata(new Thickness())); + /// /// Gets or sets the margin for the pane header. /// @@ -294,8 +267,15 @@ public Thickness PaneHeaderMargin set => this.SetValue(PaneHeaderMarginProperty, value); } + /// Identifies the dependency property. + public static readonly DependencyProperty PaneBackgroundProperty + = DependencyProperty.Register(nameof(PaneBackground), + typeof(Brush), + typeof(HamburgerMenu), + new PropertyMetadata(null)); + /// - /// Gets or sets the Brush to apply to the background of the Pane area of the control. + /// Gets or sets the Brush to apply to the background of the pane area of the HamburgerMenu. /// public Brush PaneBackground { @@ -303,8 +283,15 @@ public Brush PaneBackground set => this.SetValue(PaneBackgroundProperty, value); } + /// Identifies the dependency property. + public static readonly DependencyProperty PaneForegroundProperty + = DependencyProperty.Register(nameof(PaneForeground), + typeof(Brush), + typeof(HamburgerMenu), + new PropertyMetadata(null)); + /// - /// Gets or sets the Brush to apply to the foreground of the Pane area of the control. + /// Gets or sets the Brush to apply to the foreground of the pane area of the HamburgerMenu. /// public Brush PaneForeground { @@ -312,6 +299,21 @@ public Brush PaneForeground set => this.SetValue(PaneForegroundProperty, value); } + /// Identifies the dependency property. + public static readonly DependencyProperty IsPaneOpenProperty + = DependencyProperty.Register(nameof(IsPaneOpen), + typeof(bool), + typeof(HamburgerMenu), + new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, IsPaneOpenPropertyChangedCallback)); + + private static void IsPaneOpenPropertyChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs args) + { + if (args.NewValue != args.OldValue) + { + (dependencyObject as HamburgerMenu)?.ChangeItemFocusVisualStyle(); + } + } + /// /// Gets or sets a value indicating whether the pane is expanded to its full width. /// @@ -321,6 +323,13 @@ public bool IsPaneOpen set => this.SetValue(IsPaneOpenProperty, value); } + /// Identifies the dependency property. + public static readonly DependencyProperty ItemsSourceProperty + = DependencyProperty.Register(nameof(ItemsSource), + typeof(object), + typeof(HamburgerMenu), + new PropertyMetadata(null)); + /// /// Gets or sets an object source used to generate the content of the menu. /// @@ -330,8 +339,15 @@ public object ItemsSource set => this.SetValue(ItemsSourceProperty, value); } + /// Identifies the dependency property. + public static readonly DependencyProperty ItemContainerStyleProperty + = DependencyProperty.Register(nameof(ItemContainerStyle), + typeof(Style), + typeof(HamburgerMenu), + new PropertyMetadata(null)); + /// - /// Gets or sets the Style used for each item. + /// Gets or sets the used for each item. /// public Style ItemContainerStyle { @@ -339,8 +355,15 @@ public Style ItemContainerStyle set => this.SetValue(ItemContainerStyleProperty, value); } + /// Identifies the dependency property. + public static readonly DependencyProperty HeaderItemContainerStyleProperty + = DependencyProperty.Register(nameof(HeaderItemContainerStyle), + typeof(Style), + typeof(HamburgerMenu), + new PropertyMetadata(null)); + /// - /// Gets or sets the Style used for each header item. + /// Gets or sets the used for each header item. /// public Style HeaderItemContainerStyle { @@ -348,8 +371,15 @@ public Style HeaderItemContainerStyle set => this.SetValue(HeaderItemContainerStyleProperty, value); } + /// Identifies the dependency property. + public static readonly DependencyProperty SeparatorItemContainerStyleProperty + = DependencyProperty.Register(nameof(SeparatorItemContainerStyle), + typeof(Style), + typeof(HamburgerMenu), + new PropertyMetadata(null)); + /// - /// Gets or sets the Style used for each separator item. + /// Gets or sets the used for each separator item. /// public Style SeparatorItemContainerStyle { @@ -357,8 +387,15 @@ public Style SeparatorItemContainerStyle set => this.SetValue(SeparatorItemContainerStyleProperty, value); } + /// Identifies the dependency property. + public static readonly DependencyProperty ItemTemplateProperty + = DependencyProperty.Register(nameof(ItemTemplate), + typeof(DataTemplate), + typeof(HamburgerMenu), + new PropertyMetadata(null)); + /// - /// Gets or sets the DataTemplate used to display each item. + /// Gets or sets the used to display each item. /// public DataTemplate ItemTemplate { @@ -366,8 +403,15 @@ public DataTemplate ItemTemplate set => this.SetValue(ItemTemplateProperty, value); } + /// Identifies the dependency property. + public static readonly DependencyProperty ItemTemplateSelectorProperty + = DependencyProperty.Register(nameof(ItemTemplateSelector), + typeof(DataTemplateSelector), + typeof(HamburgerMenu), + new PropertyMetadata(null)); + /// - /// Gets or sets the DataTemplateSelector used to display each item. + /// Gets or sets the used to display each item. /// public DataTemplateSelector ItemTemplateSelector { @@ -375,24 +419,12 @@ public DataTemplateSelector ItemTemplateSelector set => this.SetValue(ItemTemplateSelectorProperty, value); } - /// - /// Gets the collection used to generate the content of the items list. - /// - /// - /// Exception thrown if ButtonsListView is not yet defined. - /// - public ItemCollection Items - { - get - { - if (this.buttonsListView == null) - { - throw new Exception("ButtonsListView is not defined yet. Please use ItemsSource instead."); - } - - return this.buttonsListView.Items; - } - } + /// Identifies the dependency property. + public static readonly DependencyProperty SelectedItemProperty + = DependencyProperty.Register(nameof(SelectedItem), + typeof(object), + typeof(HamburgerMenu), + new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault)); /// /// Gets or sets the selected menu item. @@ -403,6 +435,13 @@ public object SelectedItem set => this.SetValue(SelectedItemProperty, value); } + /// Identifies the dependency property. + public static readonly DependencyProperty SelectedIndexProperty + = DependencyProperty.Register(nameof(SelectedIndex), + typeof(int), + typeof(HamburgerMenu), + new FrameworkPropertyMetadata(-1, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault | FrameworkPropertyMetadataOptions.Journal)); + /// /// Gets or sets the selected menu index. /// @@ -412,14 +451,31 @@ public int SelectedIndex set => this.SetValue(SelectedIndexProperty, value); } + /// Identifies the dependency property. + public static readonly DependencyProperty ContentTransitionProperty + = DependencyProperty.Register(nameof(ContentTransition), + typeof(TransitionType), + typeof(HamburgerMenu), + new FrameworkPropertyMetadata(TransitionType.Normal)); + + /// + /// Gets or sets the for the which shows the selected menu item content. + /// public TransitionType ContentTransition { get => (TransitionType)this.GetValue(ContentTransitionProperty); set => this.SetValue(ContentTransitionProperty, value); } + /// Identifies the dependency property. + public static readonly DependencyProperty ItemCommandProperty + = DependencyProperty.Register(nameof(ItemCommand), + typeof(ICommand), + typeof(HamburgerMenu), + new PropertyMetadata(null)); + /// - /// Gets or sets a command which will be executed if an item is clicked by the user. + /// Gets or sets a which will be executed if an item was clicked by the user. /// public ICommand ItemCommand { @@ -427,8 +483,15 @@ public ICommand ItemCommand set => this.SetValue(ItemCommandProperty, value); } + /// Identifies the dependency property. + public static readonly DependencyProperty ItemCommandParameterProperty + = DependencyProperty.Register(nameof(ItemCommandParameter), + typeof(object), + typeof(HamburgerMenu), + new PropertyMetadata(null)); + /// - /// Gets or sets the command parameter which will be passed by the ItemCommand. + /// Gets or sets the parameter which will be passed by the . /// public object ItemCommandParameter { @@ -436,8 +499,15 @@ public object ItemCommandParameter set => this.SetValue(ItemCommandParameterProperty, value); } + /// Identifies the dependency property. + public static readonly DependencyProperty VerticalScrollBarOnLeftSideProperty + = DependencyProperty.Register(nameof(VerticalScrollBarOnLeftSide), + typeof(bool), + typeof(HamburgerMenu), + new PropertyMetadata(false)); + /// - /// Gets or sets wheather the ScrollBar of the HamburgerMenu is on the left side or on the right side. + /// Gets or sets whether the ScrollBar of the HamburgerMenu is on the left side or on the right side of the menu items. /// public bool VerticalScrollBarOnLeftSide { @@ -445,8 +515,15 @@ public bool VerticalScrollBarOnLeftSide set => this.SetValue(VerticalScrollBarOnLeftSideProperty, value); } + /// Identifies the dependency property. + public static readonly DependencyProperty ShowSelectionIndicatorProperty + = DependencyProperty.Register(nameof(ShowSelectionIndicator), + typeof(bool), + typeof(HamburgerMenu), + new PropertyMetadata(false)); + /// - /// Gets or sets wheather a selection indicator will be shown on the HamburgerMenuItem. + /// Gets or sets whether a selection indicator will be shown on the HamburgerMenuItem. /// public bool ShowSelectionIndicator { @@ -454,6 +531,16 @@ public bool ShowSelectionIndicator set => this.SetValue(ShowSelectionIndicatorProperty, value); } + /// Identifies the dependency property. + public static readonly DependencyPropertyKey ItemFocusVisualStylePropertyKey + = DependencyProperty.RegisterReadOnly(nameof(ItemFocusVisualStyle), + typeof(Style), + typeof(HamburgerMenu), + new PropertyMetadata(null)); + + /// Identifies the dependency property. + public static readonly DependencyProperty ItemFocusVisualStyleProperty = ItemFocusVisualStylePropertyKey.DependencyProperty; + /// /// Gets or sets the default FocusVisualStyle for a HamburgerMenuItem. /// This style can be override at the HamburgerMenuItem style by setting the FocusVisualStyle property. @@ -465,7 +552,26 @@ public Style ItemFocusVisualStyle } /// - /// Executes the item command which can be set by the user. + /// Gets the collection used to generate the content of the items list. + /// + /// + /// Exception thrown if ButtonsListView is not yet defined. + /// + public ItemCollection Items + { + get + { + if (this.buttonsListView == null) + { + throw new Exception("ButtonsListView is not defined yet. Please use ItemsSource instead."); + } + + return this.buttonsListView.Items; + } + } + + /// + /// Executes the . /// public void RaiseItemCommand() { diff --git a/src/MahApps.Metro/Controls/HamburgerMenu/HamburgerMenu.cs b/src/MahApps.Metro/Controls/HamburgerMenu/HamburgerMenu.cs index 0efe32ce19..82d524be90 100644 --- a/src/MahApps.Metro/Controls/HamburgerMenu/HamburgerMenu.cs +++ b/src/MahApps.Metro/Controls/HamburgerMenu/HamburgerMenu.cs @@ -5,7 +5,7 @@ namespace MahApps.Metro.Controls { /// - /// The HamburgerMenu is based on a SplitView control. By default it contains a HamburgerButton and a ListView to display menu items. + /// The HamburgerMenu is based on a control. By default it contains a HamburgerButton and a ListView to display menu items. /// [TemplatePart(Name = "HamburgerButton", Type = typeof(Button))] [TemplatePart(Name = "ButtonsListView", Type = typeof(ListBox))] @@ -48,9 +48,9 @@ public override void OnApplyTemplate() this.optionsListView.SelectionChanged -= this.OptionsListView_SelectionChanged; } - this.hamburgerButton = (Button)this.GetTemplateChild("HamburgerButton"); - this.buttonsListView = (ListBox)this.GetTemplateChild("ButtonsListView"); - this.optionsListView = (ListBox)this.GetTemplateChild("OptionsListView"); + this.hamburgerButton = this.GetTemplateChild("HamburgerButton") as Button; + this.buttonsListView = this.GetTemplateChild("ButtonsListView") as ListBox; + this.optionsListView = this.GetTemplateChild("OptionsListView") as ListBox; if (this.hamburgerButton != null) { diff --git a/src/MahApps.Metro/Controls/HamburgerMenu/HamburgerMenuListBox.cs b/src/MahApps.Metro/Controls/HamburgerMenu/HamburgerMenuListBox.cs index 932158cf60..3da142fe4d 100644 --- a/src/MahApps.Metro/Controls/HamburgerMenu/HamburgerMenuListBox.cs +++ b/src/MahApps.Metro/Controls/HamburgerMenu/HamburgerMenuListBox.cs @@ -1,6 +1,8 @@ using System.Windows; +using System.Windows.Automation; using System.Windows.Controls; using System.Windows.Data; +using MahApps.Metro.Converters; namespace MahApps.Metro.Controls { @@ -40,6 +42,148 @@ protected override void PrepareContainerForItemOverride(DependencyObject element Path = new PropertyPath(nameof(IHamburgerMenuItem.IsEnabled)), FallbackValue = true }); + + if (item is DependencyObject) + { + var helpTextPropertyMultiBinding = new MultiBinding + { + Converter = HamburgerMenuItemAccessibleConverter.Default, + Mode = BindingMode.OneWay, + FallbackValue = string.Empty, + Bindings = + { + new Binding + { + Source = hamburgerMenuItem, + Path = new PropertyPath(nameof(IHamburgerMenuItem.ToolTip)), + Mode = BindingMode.OneWay, + FallbackValue = string.Empty + }, + new Binding + { + Source = hamburgerMenuItem, + Path = new PropertyPath(AutomationProperties.HelpTextProperty), + Mode = BindingMode.OneWay, + FallbackValue = string.Empty + } + } + }; + listBoxItem.SetBinding(AutomationProperties.HelpTextProperty, helpTextPropertyMultiBinding); + + listBoxItem.SetBinding(AutomationProperties.LabeledByProperty, + new Binding + { + Source = hamburgerMenuItem, + Path = new PropertyPath(AutomationProperties.LabeledByProperty), + Mode = BindingMode.OneWay, + FallbackValue = null + }); + + var namePropertyMultiBinding = new MultiBinding + { + Converter = HamburgerMenuItemAccessibleConverter.Default, + Mode = BindingMode.OneWay, + FallbackValue = string.Empty, + Bindings = + { + new Binding + { + Source = hamburgerMenuItem, + Path = new PropertyPath(nameof(IHamburgerMenuItem.Label)), + Mode = BindingMode.OneWay, + FallbackValue = string.Empty + }, + new Binding + { + Source = hamburgerMenuItem, + Path = new PropertyPath(AutomationProperties.NameProperty), + Mode = BindingMode.OneWay, + FallbackValue = string.Empty + } + } + }; + listBoxItem.SetBinding(AutomationProperties.NameProperty, namePropertyMultiBinding); + } + else + { + listBoxItem.SetBinding(AutomationProperties.HelpTextProperty, + new Binding + { + Source = hamburgerMenuItem, + Path = new PropertyPath(nameof(IHamburgerMenuItem.ToolTip)), + Mode = BindingMode.OneWay, + FallbackValue = string.Empty + }); + + listBoxItem.SetBinding(AutomationProperties.NameProperty, + new Binding + { + Source = hamburgerMenuItem, + Path = new PropertyPath(nameof(IHamburgerMenuItem.Label)), + Mode = BindingMode.OneWay, + FallbackValue = string.Empty + }); + } + } + + if (item is IHamburgerMenuHeaderItem hamburgerMenuHeaderItem) + { + if (item is DependencyObject) + { + listBoxItem.SetBinding(AutomationProperties.HelpTextProperty, + new Binding + { + Source = hamburgerMenuHeaderItem, + Path = new PropertyPath(AutomationProperties.HelpTextProperty), + Mode = BindingMode.OneWay, + FallbackValue = string.Empty + }); + + listBoxItem.SetBinding(AutomationProperties.LabeledByProperty, + new Binding + { + Source = hamburgerMenuHeaderItem, + Path = new PropertyPath(AutomationProperties.LabeledByProperty), + Mode = BindingMode.OneWay, + FallbackValue = null + }); + + var namePropertyMultiBinding = new MultiBinding + { + Converter = HamburgerMenuItemAccessibleConverter.Default, + Mode = BindingMode.OneWay, + FallbackValue = string.Empty, + Bindings = + { + new Binding + { + Source = hamburgerMenuHeaderItem, + Path = new PropertyPath(nameof(IHamburgerMenuHeaderItem.Label)), + Mode = BindingMode.OneWay, + FallbackValue = string.Empty + }, + new Binding + { + Source = hamburgerMenuHeaderItem, + Path = new PropertyPath(AutomationProperties.NameProperty), + Mode = BindingMode.OneWay, + FallbackValue = string.Empty + } + } + }; + listBoxItem.SetBinding(AutomationProperties.NameProperty, namePropertyMultiBinding); + } + else + { + listBoxItem.SetBinding(AutomationProperties.NameProperty, + new Binding + { + Source = hamburgerMenuHeaderItem, + Path = new PropertyPath(nameof(IHamburgerMenuHeaderItem.Label)), + Mode = BindingMode.OneWay, + FallbackValue = string.Empty + }); + } } } } @@ -52,6 +196,9 @@ protected override void ClearContainerForItemOverride(DependencyObject element, { BindingOperations.ClearBinding(listBoxItem, VisibilityProperty); BindingOperations.ClearBinding(listBoxItem, IsEnabledProperty); + BindingOperations.ClearBinding(listBoxItem, AutomationProperties.HelpTextProperty); + BindingOperations.ClearBinding(listBoxItem, AutomationProperties.LabeledByProperty); + BindingOperations.ClearBinding(listBoxItem, AutomationProperties.NameProperty); } } } diff --git a/src/MahApps.Metro/Controls/HamburgerMenu/MenuItems/IHamburgerMenuItem.cs b/src/MahApps.Metro/Controls/HamburgerMenu/MenuItems/IHamburgerMenuItem.cs index 69ae640707..7e27deb089 100644 --- a/src/MahApps.Metro/Controls/HamburgerMenu/MenuItems/IHamburgerMenuItem.cs +++ b/src/MahApps.Metro/Controls/HamburgerMenu/MenuItems/IHamburgerMenuItem.cs @@ -2,6 +2,16 @@ { public interface IHamburgerMenuItem { + /// + /// Gets or sets a value that specifies label to display. + /// + string Label { get; set; } + + /// + /// Gets or sets a value that specifies ToolTip to display. + /// + object ToolTip { get; set; } + /// /// Gets or sets a value indicating whether this item is enabled in the user interface (UI). /// diff --git a/src/MahApps.Metro/Converters/HamburgerMenuItemAccessibleConverter.cs b/src/MahApps.Metro/Converters/HamburgerMenuItemAccessibleConverter.cs new file mode 100644 index 0000000000..4ecc943f6a --- /dev/null +++ b/src/MahApps.Metro/Converters/HamburgerMenuItemAccessibleConverter.cs @@ -0,0 +1,41 @@ +using System; +using System.Globalization; +using System.Linq; +using System.Windows.Data; + +namespace MahApps.Metro.Converters +{ + [ValueConversion(typeof(object), typeof(object))] + internal sealed class HamburgerMenuItemAccessibleConverter : IMultiValueConverter + { + /// Gets the default instance + internal static HamburgerMenuItemAccessibleConverter Default { get; } = new HamburgerMenuItemAccessibleConverter(); + + public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) + { + if (values is null) + { + return Binding.DoNothing; + } + + var automationPropertiesValue = values.ElementAtOrDefault(1) as string; + if (!string.IsNullOrEmpty(automationPropertiesValue)) + { + return automationPropertiesValue; + } + + var menuItemValue = values.ElementAtOrDefault(0) as string; + if (!string.IsNullOrEmpty(menuItemValue)) + { + return menuItemValue; + } + + return Binding.DoNothing; + } + + public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) + { + return targetTypes.Select(t => Binding.DoNothing).ToArray(); + } + } +} \ No newline at end of file diff --git a/src/MahApps.Metro/Themes/HamburgerMenu.xaml b/src/MahApps.Metro/Themes/HamburgerMenu.xaml index feb4b5f714..ab269863c8 100644 --- a/src/MahApps.Metro/Themes/HamburgerMenu.xaml +++ b/src/MahApps.Metro/Themes/HamburgerMenu.xaml @@ -10,6 +10,7 @@ + diff --git a/src/MahApps.Metro/Themes/HamburgerMenuTemplate.xaml b/src/MahApps.Metro/Themes/HamburgerMenuTemplate.xaml index 80790c8043..265c45ad43 100644 --- a/src/MahApps.Metro/Themes/HamburgerMenuTemplate.xaml +++ b/src/MahApps.Metro/Themes/HamburgerMenuTemplate.xaml @@ -424,7 +424,9 @@ Width="{TemplateBinding HamburgerWidth}" Height="{TemplateBinding HamburgerHeight}" Padding="{TemplateBinding HamburgerMargin}" - AutomationProperties.Name="Main button" + AutomationProperties.AutomationId="HamburgerButton" + AutomationProperties.HelpText="{TemplateBinding HamburgerButtonHelpText}" + AutomationProperties.Name="{TemplateBinding HamburgerButtonName}" ContentTemplate="{TemplateBinding HamburgerButtonTemplate}" DockPanel.Dock="Left" Foreground="{TemplateBinding PaneForeground}"