Skip to content

Commit

Permalink
HamburgerMenu: ItemContainerStyle and OptionsItemContainerStyle prope…
Browse files Browse the repository at this point in the history
…rties

  This makes it easier to change the inner styles for the items (and option items)
  • Loading branch information
punker76 committed Oct 23, 2017
1 parent b189e86 commit 92ab747
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
Expand Up @@ -15,6 +15,11 @@ public partial class HamburgerMenu
/// </summary>
public static readonly DependencyProperty OptionsItemsSourceProperty = DependencyProperty.Register(nameof(OptionsItemsSource), typeof(object), typeof(HamburgerMenu), new PropertyMetadata(null));

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

/// <summary>
/// Identifies the <see cref="OptionsItemTemplate"/> dependency property.
/// </summary>
Expand Down Expand Up @@ -59,6 +64,15 @@ public object OptionsItemsSource
set { SetValue(OptionsItemsSourceProperty, value); }
}

/// <summary>
/// Gets or sets the Style used for each item in the options.
/// </summary>
public Style OptionsItemContainerStyle
{
get { return (Style)GetValue(OptionsItemContainerStyleProperty); }
set { SetValue(OptionsItemContainerStyleProperty, value); }
}

/// <summary>
/// Gets or sets the DataTemplate used to display each item in the options.
/// </summary>
Expand Down
Expand Up @@ -51,6 +51,11 @@ public partial class HamburgerMenu
/// </summary>
public static readonly DependencyProperty ItemsSourceProperty = DependencyProperty.Register(nameof(ItemsSource), typeof(object), typeof(HamburgerMenu), new PropertyMetadata(null));

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

/// <summary>
/// Identifies the <see cref="ItemTemplate"/> dependency property.
/// </summary>
Expand Down Expand Up @@ -163,6 +168,15 @@ public object ItemsSource
set { SetValue(ItemsSourceProperty, value); }
}

/// <summary>
/// Gets or sets the Style used for each item.
/// </summary>
public Style ItemContainerStyle
{
get { return (Style)GetValue(ItemContainerStyleProperty); }
set { SetValue(ItemContainerStyleProperty, value); }
}

/// <summary>
/// Gets or sets the DataTemplate used to display each item.
/// </summary>
Expand Down
7 changes: 5 additions & 2 deletions src/MahApps.Metro/MahApps.Metro/Themes/HamburgerMenu.xaml
Expand Up @@ -164,7 +164,7 @@
</Setter>
</Style>

<Style x:Key="HamburgerListBoxItemStyle"
<Style x:Key="HambugerMenuItemStyle"
BasedOn="{StaticResource MetroListBoxItem}"
TargetType="{x:Type ListBoxItem}">
<Setter Property="Background" Value="Transparent" />
Expand All @@ -189,7 +189,6 @@
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="ItemContainerStyle" Value="{StaticResource HamburgerListBoxItemStyle}" />
<Setter Property="ScrollViewer.CanContentScroll" Value="False" />
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled" />
<Setter Property="Template">
Expand Down Expand Up @@ -237,9 +236,11 @@
</Setter.Value>
</Setter>
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="ItemContainerStyle" Value="{StaticResource HambugerMenuItemStyle}" />
<Setter Property="KeyboardNavigation.ControlTabNavigation" Value="Local" />
<Setter Property="KeyboardNavigation.DirectionalNavigation" Value="Local" />
<Setter Property="KeyboardNavigation.TabNavigation" Value="Local" />
<Setter Property="OptionsItemContainerStyle" Value="{StaticResource HambugerMenuItemStyle}" />
<Setter Property="PaneBackground" Value="{DynamicResource MahApps.Metro.HamburgerMenu.PaneBackgroundBrush}" />
<Setter Property="PaneForeground" Value="{DynamicResource MahApps.Metro.HamburgerMenu.PaneForegroundBrush}" />
<Setter Property="Template">
Expand Down Expand Up @@ -280,6 +281,7 @@
Controls:ScrollViewerHelper.VerticalScrollBarOnLeftSide="{TemplateBinding VerticalScrollBarOnLeftSide}"
AutomationProperties.Name="Menu items"
Foreground="{TemplateBinding PaneForeground}"
ItemContainerStyle="{TemplateBinding ItemContainerStyle}"
ItemTemplate="{TemplateBinding ItemTemplate}"
ItemTemplateSelector="{TemplateBinding ItemTemplateSelector}"
ItemsSource="{TemplateBinding ItemsSource}"
Expand All @@ -296,6 +298,7 @@
VerticalAlignment="Bottom"
AutomationProperties.Name="Option items"
Foreground="{TemplateBinding PaneForeground}"
ItemContainerStyle="{TemplateBinding OptionsItemContainerStyle}"
ItemTemplate="{TemplateBinding OptionsItemTemplate}"
ItemTemplateSelector="{TemplateBinding OptionsItemTemplateSelector}"
ItemsSource="{TemplateBinding OptionsItemsSource}"
Expand Down

0 comments on commit 92ab747

Please sign in to comment.