XAML-Map-Control/MapUiTools/WPF/MenuButton.WPF.cs

34 lines
899 B
C#
Raw Normal View History

using System.Windows;
2022-01-11 19:42:12 +01:00
using System.Windows.Controls;
using System.Windows.Markup;
2022-01-11 19:42:12 +01:00
namespace MapControl.UiTools
{
[ContentProperty(nameof(Items))]
public partial class MenuButton
2022-01-11 19:42:12 +01:00
{
2022-01-24 23:07:36 +01:00
static MenuButton()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(MenuButton), new FrameworkPropertyMetadata(typeof(MenuButton)));
}
public MenuButton()
2022-01-11 19:42:12 +01:00
{
ContextMenu = new ContextMenu();
2025-12-09 20:17:41 +01:00
DataContextChanged += (_, e) => ContextMenu.DataContext = e.NewValue;
Loaded += async (_, _) => await Initialize();
Click += (_, _) => ContextMenu.IsOpen = true;
2022-01-11 19:42:12 +01:00
}
public string Icon
2022-01-11 19:42:12 +01:00
{
get => Content as string;
set => Content = value;
2022-01-11 19:42:12 +01:00
}
public ContextMenu Menu => ContextMenu;
2022-01-11 19:42:12 +01:00
public ItemCollection Items => ContextMenu.Items;
2022-01-11 19:42:12 +01:00
}
}