mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-04-20 22:05:07 +00:00
New menu item implementation based directly on MenuItem/ToggleMenuFlyoutItem
This commit is contained in:
parent
11cd45c099
commit
e06dcc5155
12 changed files with 335 additions and 412 deletions
42
MapUiTools/Avalonia/MapMenuItem.Avalonia.cs
Normal file
42
MapUiTools/Avalonia/MapMenuItem.Avalonia.cs
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Media;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace MapControl.UiTools
|
||||
{
|
||||
public class MapMenuItem : MenuItem
|
||||
{
|
||||
public MapMenuItem()
|
||||
{
|
||||
Icon = new TextBlock
|
||||
{
|
||||
FontFamily = new("Segoe MDL2 Assets"),
|
||||
FontWeight = FontWeight.Black,
|
||||
VerticalAlignment = Avalonia.Layout.VerticalAlignment.Center,
|
||||
};
|
||||
}
|
||||
|
||||
public string Text
|
||||
{
|
||||
get => Header as string;
|
||||
set => Header = value;
|
||||
}
|
||||
|
||||
protected IEnumerable<MapMenuItem> ParentMenuItems => (Parent as ItemsControl)?.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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,81 +1,37 @@
|
|||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Media;
|
||||
using Avalonia.Metadata;
|
||||
using Avalonia.Styling;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace MapControl
|
||||
namespace MapControl.UiTools
|
||||
{
|
||||
public class ToggleMenuFlyoutItem : MenuItem
|
||||
public partial class MenuButton
|
||||
{
|
||||
internal static readonly FontFamily SymbolFont = new("Segoe MDL2 Assets");
|
||||
|
||||
private readonly TextBlock icon = new()
|
||||
{
|
||||
FontFamily = SymbolFont,
|
||||
FontWeight = FontWeight.Black,
|
||||
VerticalAlignment = Avalonia.Layout.VerticalAlignment.Center,
|
||||
};
|
||||
|
||||
public ToggleMenuFlyoutItem(string text, object item, EventHandler<RoutedEventArgs> click)
|
||||
{
|
||||
Icon = icon;
|
||||
Header = text;
|
||||
Tag = item;
|
||||
Click += click;
|
||||
}
|
||||
|
||||
protected override Type StyleKeyOverride => typeof(MenuItem);
|
||||
|
||||
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs args)
|
||||
{
|
||||
base.OnPropertyChanged(args);
|
||||
|
||||
if (args.Property == IsCheckedProperty)
|
||||
{
|
||||
icon.Text = (bool)args.NewValue ? "\uE73E" : ""; // CheckMark
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class MenuButton : Button
|
||||
{
|
||||
protected MenuButton(string icon)
|
||||
public MenuButton()
|
||||
{
|
||||
var style = new Style();
|
||||
style.Setters.Add(new Setter(TextBlock.FontFamilyProperty, ToggleMenuFlyoutItem.SymbolFont));
|
||||
style.Setters.Add(new Setter(TextBlock.FontFamilyProperty, new FontFamily("Segoe MDL2 Assets")));
|
||||
style.Setters.Add(new Setter(TextBlock.FontSizeProperty, 20d));
|
||||
style.Setters.Add(new Setter(PaddingProperty, new Thickness(8)));
|
||||
Styles.Add(style);
|
||||
|
||||
Content = icon;
|
||||
Flyout = new MenuFlyout();
|
||||
Loaded += async (s, e) => await Initialize();
|
||||
}
|
||||
|
||||
public string Icon
|
||||
{
|
||||
get => Content as string;
|
||||
set => Content = value;
|
||||
}
|
||||
|
||||
public MenuFlyout Menu => (MenuFlyout)Flyout;
|
||||
|
||||
[Content]
|
||||
public ItemCollection Items => Menu.Items;
|
||||
|
||||
protected override Type StyleKeyOverride => typeof(Button);
|
||||
|
||||
protected MenuFlyout CreateMenu()
|
||||
{
|
||||
var menu = new MenuFlyout();
|
||||
Flyout = menu;
|
||||
return menu;
|
||||
}
|
||||
|
||||
protected IEnumerable<ToggleMenuFlyoutItem> GetMenuItems()
|
||||
{
|
||||
return ((MenuFlyout)Flyout).Items.OfType<ToggleMenuFlyoutItem>();
|
||||
}
|
||||
|
||||
protected static MenuItem CreateMenuItem(string text, object item, EventHandler<RoutedEventArgs> click)
|
||||
{
|
||||
return new ToggleMenuFlyoutItem(text, item, click);
|
||||
}
|
||||
|
||||
protected static Separator CreateSeparator()
|
||||
{
|
||||
return new Separator();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue