Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(GH-3839) Allow setting AutomationProperties for HamburgerMenuItem #3856

Merged
merged 5 commits into from
Jun 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
<!-- Items -->
<Controls:HamburgerMenu.ItemsSource>
<Controls:HamburgerMenuItemCollection>
<Controls:HamburgerMenuHeaderItem Label="Pictures" />
<Controls:HamburgerMenuHeaderItem AutomationProperties.Name="The Pictures Header" Label="Pictures" />
<Controls:HamburgerMenuGlyphItem Glyph="/Assets/Photos/BigFourSummerHeat.png" Label="Big four summer heat" />
<Controls:HamburgerMenuGlyphItem Glyph="/Assets/Photos/BisonBadlandsChillin.png" Label="Bison badlands Chillin" />
<Controls:HamburgerMenuSeparatorItem />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,10 @@
<!-- Items -->
<Controls:HamburgerMenu.ItemsSource>
<Controls:HamburgerMenuItemCollection>
<Controls:HamburgerMenuGlyphItem Glyph="/Assets/Photos/BigFourSummerHeat.png" Label="Big four summer heat" />
<Controls:HamburgerMenuGlyphItem AutomationProperties.HelpText="First Item shows BigFourSummerHeat"
AutomationProperties.Name="First Item"
Glyph="/Assets/Photos/BigFourSummerHeat.png"
Label="Big four summer heat" />
<Controls:HamburgerMenuGlyphItem Glyph="/Assets/Photos/BisonBadlandsChillin.png" Label="Bison badlands Chillin" />
<Controls:HamburgerMenuGlyphItem Glyph="/Assets/Photos/GiantSlabInOregon.png" Label="Giant slab in Oregon" />
<Controls:HamburgerMenuGlyphItem Glyph="/Assets/Photos/LakeAnnMushroom.png" Label="Lake Ann Mushroom" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace MahApps.Metro.Controls
{
/// <summary>
/// EventArgs used for the <see cref="HamburgerMenu"/> ItemClick and OptionsItemClick event.
/// EventArgs used for the <see cref="HamburgerMenu.ItemClick"/> and <see cref="HamburgerMenu.OptionsItemClick"/> events.
/// </summary>
public class ItemClickEventArgs : RoutedEventArgs
{
Expand All @@ -25,18 +25,18 @@ public ItemClickEventArgs(RoutedEvent routedEvent, object source)
}

/// <summary>
/// Gets the clicked item
/// Gets the clicked item (options item).
/// </summary>
public object ClickedItem { get; internal set; }
}

/// <summary>
/// RoutedEventHandler used for the <see cref="HamburgerMenu"/> ItemClick and OptionsItemClick event.
/// RoutedEventHandler used for the <see cref="HamburgerMenu.ItemClick"/> and <see cref="HamburgerMenu.OptionsItemClick"/> events.
/// </summary>
public delegate void ItemClickRoutedEventHandler(object sender, ItemClickEventArgs args);

/// <summary>
/// EventArgs used for the <see cref="HamburgerMenu"/> ItemInvoked event.
/// EventArgs used for the <see cref="HamburgerMenu.ItemInvoked"/> event.
/// </summary>
public class HamburgerMenuItemInvokedEventArgs : RoutedEventArgs
{
Expand All @@ -58,7 +58,7 @@ public HamburgerMenuItemInvokedEventArgs(RoutedEvent routedEvent, object source)
}

/// <summary>
/// Gets the invoked item
/// Gets the invoked item.
/// </summary>
public object InvokedItem { get; internal set; }

Expand All @@ -69,7 +69,7 @@ public HamburgerMenuItemInvokedEventArgs(RoutedEvent routedEvent, object source)
}

/// <summary>
/// RoutedEventHandler used for the <see cref="HamburgerMenu"/> ItemInvoked event.
/// RoutedEventHandler used for the <see cref="HamburgerMenu.ItemInvoked"/> event.
/// </summary>
public delegate void HamburgerMenuItemInvokedRoutedEventHandler(object sender, HamburgerMenuItemInvokedEventArgs args);
}
30 changes: 22 additions & 8 deletions src/MahApps.Metro/Controls/HamburgerMenu/HamburgerMenu.Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ namespace MahApps.Metro.Controls
public partial class HamburgerMenu
{
/// <summary>Identifies the <see cref="ItemClick"/> routed event.</summary>
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));

/// <summary>
/// Event raised when an item is clicked
Expand All @@ -18,7 +22,11 @@ public event ItemClickRoutedEventHandler ItemClick
}

/// <summary>Identifies the <see cref="OptionsItemClick"/> routed event.</summary>
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));

/// <summary>
/// Event raised when an options' item is clicked
Expand All @@ -30,7 +38,11 @@ public event ItemClickRoutedEventHandler OptionsItemClick
}

/// <summary>Identifies the <see cref="ItemInvoked"/> routed event.</summary>
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));

/// <summary>
/// Event raised when an item is invoked
Expand All @@ -42,7 +54,11 @@ public event HamburgerMenuItemInvokedRoutedEventHandler ItemInvoked
}

/// <summary>Identifies the <see cref="HamburgerButtonClick"/> routed event.</summary>
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));

/// <summary>
/// Event raised when the hamburger button is clicked
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Windows;
using System.Windows.Automation;
using System.Windows.Controls;

namespace MahApps.Metro.Controls
Expand All @@ -7,87 +8,154 @@ namespace MahApps.Metro.Controls
public partial class HamburgerMenu
{
/// <summary>Identifies the <see cref="HamburgerWidth"/> dependency property.</summary>
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));

/// <summary>
/// Gets or sets HamburgerMenu button's <see cref="FrameworkElement.Width"/>.
/// </summary>
public double HamburgerWidth
{
get => (double)this.GetValue(HamburgerWidthProperty);
set => this.SetValue(HamburgerWidthProperty, value);
}

/// <summary>Identifies the <see cref="HamburgerHeight"/> dependency property.</summary>
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));

/// <summary>
/// Gets or sets the <see cref="FrameworkElement.Height"/> for the HamburgerMenu button.
/// </summary>
public double HamburgerHeight
{
get => (double)this.GetValue(HamburgerHeightProperty);
set => this.SetValue(HamburgerHeightProperty, value);
}

/// <summary>Identifies the <see cref="HamburgerMargin"/> dependency property.</summary>
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()));

/// <summary>
/// Gets or sets the margin for the HamburgerMenu button.
/// </summary>
public Thickness HamburgerMargin
{
get => (Thickness)this.GetValue(HamburgerMarginProperty);
set => this.SetValue(HamburgerMarginProperty, value);
}

/// <summary>Identifies the <see cref="HamburgerVisibility"/> dependency property.</summary>
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));

/// <summary>Identifies the <see cref="HamburgerButtonStyle"/> dependency property.</summary>
public static readonly DependencyProperty HamburgerButtonStyleProperty = DependencyProperty.Register(nameof(HamburgerButtonStyle), typeof(Style), typeof(HamburgerMenu), new PropertyMetadata(null));
/// <summary>
/// Gets or sets the <see cref="UIElement.Visibility"/> for the HamburgerMenu button.
/// </summary>
public Visibility HamburgerVisibility
{
get => (Visibility)this.GetValue(HamburgerVisibilityProperty);
set => this.SetValue(HamburgerVisibilityProperty, value);
}

/// <summary>Identifies the <see cref="HamburgerButtonTemplate"/> dependency property.</summary>
public static readonly DependencyProperty HamburgerButtonTemplateProperty = DependencyProperty.Register(nameof(HamburgerButtonTemplate), typeof(DataTemplate), typeof(HamburgerMenu), new PropertyMetadata(null));
/// <summary>Identifies the <see cref="HamburgerButtonStyle"/> dependency property.</summary>
public static readonly DependencyProperty HamburgerButtonStyleProperty
= DependencyProperty.Register(nameof(HamburgerButtonStyle),
typeof(Style),
typeof(HamburgerMenu),
new PropertyMetadata(null));

/// <summary>
/// Gets or sets the Style used for the hamburger button.
/// Gets or sets the <see cref="FrameworkElement.Style"/> for the HamburgerMenu button.
/// </summary>
public Style HamburgerButtonStyle
{
get => (Style)this.GetValue(HamburgerButtonStyleProperty);
set => this.SetValue(HamburgerButtonStyleProperty, value);
}

/// <summary>Identifies the <see cref="HamburgerButtonTemplate"/> dependency property.</summary>
public static readonly DependencyProperty HamburgerButtonTemplateProperty
= DependencyProperty.Register(nameof(HamburgerButtonTemplate),
typeof(DataTemplate),
typeof(HamburgerMenu),
new PropertyMetadata(null));

/// <summary>
/// Gets or sets a template for the hamburger button.
/// Gets or sets the <see cref="ContentControl.ContentTemplate"/> for the HamburgerMenu button.
/// </summary>
public DataTemplate HamburgerButtonTemplate
{
get => (DataTemplate)this.GetValue(HamburgerButtonTemplateProperty);
set => this.SetValue(HamburgerButtonTemplateProperty, value);
}

/// <summary>Identifies the <see cref="HamburgerMenuHeaderTemplate"/> dependency property.</summary>
public static readonly DependencyProperty HamburgerMenuHeaderTemplateProperty = DependencyProperty.Register(nameof(HamburgerMenuHeaderTemplate), typeof(DataTemplate), typeof(HamburgerMenu), new PropertyMetadata(null));
/// <summary>Identifies the <see cref="HamburgerButtonName"/> dependency property.</summary>
public static readonly DependencyProperty HamburgerButtonNameProperty
= DependencyProperty.Register(nameof(HamburgerButtonName),
typeof(string),
typeof(HamburgerMenu),
new UIPropertyMetadata(string.Empty),
new ValidateValueCallback(IsNotNull));

/// <summary>
/// Gets or sets a template for the hamburger pane header.
/// Gets or sets the<see cref= "AutomationProperties.NameProperty" /> for the HamburgerMenu button.
/// </summary>
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);
}

/// <summary>
/// Gets or sets main button's width.
/// </summary>
public double HamburgerWidth
{
get => (double)this.GetValue(HamburgerWidthProperty);
set => this.SetValue(HamburgerWidthProperty, value);
}
/// <summary>Identifies the <see cref="HamburgerButtonHelpText"/> dependency property.</summary>
public static readonly DependencyProperty HamburgerButtonHelpTextProperty
= DependencyProperty.Register(nameof(HamburgerButtonHelpText),
typeof(string),
typeof(HamburgerMenu),
new UIPropertyMetadata(string.Empty),
new ValidateValueCallback(IsNotNull));

/// <summary>
/// Gets or sets main button's height.
/// Gets or sets the <see cref="AutomationProperties.HelpTextProperty"/> for the HamburgerMenu button.
/// </summary>
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);
}

/// <summary>Identifies the <see cref="HamburgerMenuHeaderTemplate"/> dependency property.</summary>
public static readonly DependencyProperty HamburgerMenuHeaderTemplateProperty
= DependencyProperty.Register(nameof(HamburgerMenuHeaderTemplate),
typeof(DataTemplate),
typeof(HamburgerMenu),
new PropertyMetadata(null));

/// <summary>
/// Gets or sets main button's margin.
/// Gets or sets the <see cref="ContentControl.ContentTemplate"/> for the HamburgerMenu pane header.
/// </summary>
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);
}

/// <summary>
/// Gets or sets main button's visibility.
/// </summary>
public Visibility HamburgerVisibility
private static bool IsNotNull(object value)
{
get => (Visibility)this.GetValue(HamburgerVisibilityProperty);
set => this.SetValue(HamburgerVisibilityProperty, value);
return value != null;
}
}
}
Loading