XAML-Map-Control/MapUiTools/Avalonia/MapMenuItem.Avalonia.cs

46 lines
1.2 KiB
C#
Raw Normal View History

using Avalonia;
using Avalonia.Controls;
using Avalonia.Media;
using System;
using System.Collections.Generic;
using System.Linq;
namespace MapControl.UiTools
{
2025-03-26 19:58:47 +01:00
public abstract partial class MapMenuItem : MenuItem
{
2025-03-26 19:58:47 +01:00
protected MapMenuItem()
{
Icon = new TextBlock
{
2025-12-05 14:44:33 +01:00
FontFamily = new FontFamily("Segoe MDL2 Assets"),
FontWeight = FontWeight.Black,
VerticalAlignment = Avalonia.Layout.VerticalAlignment.Center,
};
2025-03-26 19:58:47 +01:00
2025-09-20 14:02:42 +02:00
Loaded += (s, e) => Initialize();
Click += (s, e) => Execute();
}
public string Text
{
get => Header as string;
set => Header = value;
}
2025-03-21 18:03:57 +01:00
protected IEnumerable<MapMenuItem> ParentMenuItems => ((ItemsControl)Parent).Items.OfType<MapMenuItem>();
protected override Type StyleKeyOverride => typeof(MenuItem);
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs args)
{
base.OnPropertyChanged(args);
if (args.Property == IsCheckedProperty)
{
((TextBlock)Icon).Text = (bool)args.NewValue ? "\uE73E" : ""; // CheckMark
}
}
}
}