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

51 lines
1.3 KiB
C#
Raw Normal View History

2022-01-11 19:42:12 +01:00
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
2024-02-03 21:01:53 +01:00
// Copyright © 2024 Clemens Fischer
2022-01-11 19:42:12 +01:00
// Licensed under the Microsoft Public License (Ms-PL)
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
namespace MapControl.UiTools
{
public class MenuButton : Button
{
2022-01-24 23:07:36 +01:00
static MenuButton()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(MenuButton), new FrameworkPropertyMetadata(typeof(MenuButton)));
}
2022-01-11 19:42:12 +01:00
protected MenuButton(string icon)
{
Content = icon;
Click += (s, e) => ContextMenu.IsOpen = true;
}
protected ContextMenu CreateMenu()
{
var menu = new ContextMenu();
ContextMenu = menu;
return menu;
}
protected IEnumerable<MenuItem> GetMenuItems()
{
return ContextMenu.Items.OfType<MenuItem>();
}
protected static MenuItem CreateMenuItem(string text, object item, RoutedEventHandler click)
{
var menuItem = new MenuItem { Header = text, Tag = item };
menuItem.Click += click;
return menuItem;
}
protected static Separator CreateSeparator()
{
return new Separator();
}
}
}