更新
This commit is contained in:
67
WPFDark/Controls/Internals/BiaHamburgerMenuHost.xaml.cs
Normal file
67
WPFDark/Controls/Internals/BiaHamburgerMenuHost.xaml.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
using WPFDark.Internals;
|
||||
|
||||
namespace WPFDark.Controls.Internals
|
||||
{
|
||||
internal class BiaHamburgerMenuHost : Control
|
||||
{
|
||||
#region HamburgerMenuItem
|
||||
|
||||
public BiaHamburgerMenu? MenuItem
|
||||
{
|
||||
get => _menuItem;
|
||||
set
|
||||
{
|
||||
if (value != _menuItem)
|
||||
SetValue(MenuItemProperty, value);
|
||||
}
|
||||
}
|
||||
|
||||
private BiaHamburgerMenu? _menuItem;
|
||||
|
||||
public static readonly DependencyProperty MenuItemProperty =
|
||||
DependencyProperty.Register(
|
||||
nameof(MenuItem),
|
||||
typeof(BiaHamburgerMenu),
|
||||
typeof(BiaHamburgerMenuHost),
|
||||
new PropertyMetadata(
|
||||
default,
|
||||
(s, e) =>
|
||||
{
|
||||
var self = (BiaHamburgerMenuHost) s;
|
||||
self._menuItem = (BiaHamburgerMenu)e.NewValue;
|
||||
|
||||
self.UpdateMenuItem();
|
||||
}));
|
||||
|
||||
#endregion
|
||||
|
||||
static BiaHamburgerMenuHost()
|
||||
{
|
||||
DefaultStyleKeyProperty.OverrideMetadata(typeof(BiaHamburgerMenuHost),
|
||||
new FrameworkPropertyMetadata(typeof(BiaHamburgerMenuHost)));
|
||||
}
|
||||
|
||||
public override void OnApplyTemplate()
|
||||
{
|
||||
UpdateMenuItem();
|
||||
}
|
||||
|
||||
private void UpdateMenuItem()
|
||||
{
|
||||
var menu = this.Descendants().OfType<Menu?>().FirstOrDefault();
|
||||
if (menu is null)
|
||||
return;
|
||||
|
||||
menu.Items.Clear();
|
||||
|
||||
if (MenuItem is null)
|
||||
return;
|
||||
|
||||
menu.Items.Add(MenuItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user