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

33 lines
809 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
2026-04-13 17:14:49 +02:00
namespace MapControl.UiTools;
[ContentProperty(nameof(Items))]
public partial class MenuButton
2022-01-11 19:42:12 +01:00
{
2026-04-13 17:14:49 +02:00
static MenuButton()
2022-01-11 19:42:12 +01:00
{
2026-04-13 17:14:49 +02:00
DefaultStyleKeyProperty.OverrideMetadata(typeof(MenuButton), new FrameworkPropertyMetadata(typeof(MenuButton)));
}
2022-01-24 23:07:36 +01:00
2026-04-13 17:14:49 +02:00
public MenuButton()
{
ContextMenu = new ContextMenu();
DataContextChanged += (_, e) => ContextMenu.DataContext = e.NewValue;
Loaded += async (_, _) => await Initialize();
Click += (_, _) => ContextMenu.IsOpen = true;
}
2022-01-11 19:42:12 +01:00
2026-04-13 17:14:49 +02:00
public string Icon
{
get => Content as string;
set => Content = value;
}
2022-01-11 19:42:12 +01:00
2026-04-13 17:14:49 +02:00
public ContextMenu Menu => ContextMenu;
2022-01-11 19:42:12 +01:00
2026-04-13 17:14:49 +02:00
public ItemCollection Items => ContextMenu.Items;
2022-01-11 19:42:12 +01:00
}