add expandmode property step1

This commit is contained in:
NaBian 2019-05-04 15:10:15 +08:00
parent 145c47711f
commit bb27ef7635
3 changed files with 35 additions and 1 deletions

View File

@ -6,7 +6,7 @@
Background="{DynamicResource RegionBrush}">
<Grid>
<controls:SideMenu BorderThickness="1" Width="200" Margin="32">
<controls:SideMenu ExpandMode="ShowOne" BorderThickness="1" Width="200" Margin="32">
<controls:SideMenuItem Header="Overview">
<controls:SideMenuItem.Icon>
<Image Source="/HandyControlDemo;component/Resources/Img/DevOps/DevOps-Overview.png" Width="24" Height="24"/>

View File

@ -1,5 +1,6 @@
using System.Windows;
using HandyControl.Data;
using HandyControl.Data.Enum;
namespace HandyControl.Controls
{
@ -38,10 +39,12 @@ namespace HandyControl.Controls
if (_selectedHeader != null)
{
_selectedHeader.IsSelected = false;
SwitchPanelArea(_selectedHeader);
}
_selectedHeader = item;
_selectedHeader.IsSelected = true;
SwitchPanelArea(_selectedHeader);
}
if (_isItemSelected)
@ -57,8 +60,30 @@ namespace HandyControl.Controls
}
}
private void SwitchPanelArea(SideMenuItem oldItem)
{
switch (ExpandMode)
{
case ExpandMode.ShowAll:
return;
case ExpandMode.ShowOne:
case ExpandMode.Accordion:
oldItem.SwitchPanelArea(oldItem.IsSelected);
break;
}
}
protected override DependencyObject GetContainerForItemOverride() => new SideMenuItem();
protected override bool IsItemItsOwnContainerOverride(object item) => item is SideMenuItem;
public static readonly DependencyProperty ExpandModeProperty = DependencyProperty.Register(
"ExpandMode", typeof(ExpandMode), typeof(SideMenu), new PropertyMetadata(default(ExpandMode)));
public ExpandMode ExpandMode
{
get => (ExpandMode) GetValue(ExpandModeProperty);
set => SetValue(ExpandModeProperty, value);
}
}
}

View File

@ -2,6 +2,7 @@
using System.Windows;
using System.Windows.Input;
using HandyControl.Data;
using HandyControl.Tools.Extension;
namespace HandyControl.Controls
{
@ -89,5 +90,13 @@ namespace HandyControl.Controls
}
}
}
internal void SwitchPanelArea(bool close)
{
if (Role == SideMenuItemRole.Header)
{
ItemsHost.Show(close);
}
}
}
}