Move event handlers to base class

This commit is contained in:
ClemensFischer 2025-03-26 19:58:47 +01:00
parent a9c1a4c320
commit 5680c9c25f
5 changed files with 85 additions and 52 deletions

View file

@ -31,28 +31,9 @@ namespace MapControl.UiTools
public Func<Task<FrameworkElement>> MapLayerFactory { get; set; }
public MapLayerMenuItem()
protected override bool GetIsChecked(MapBase map)
{
Loaded += (s, e) =>
{
if (DataContext is MapBase map)
{
IsChecked = map.Children.Contains(MapLayer);
}
};
Click += async (s, e) =>
{
if (DataContext is MapBase map)
{
await Execute(map);
foreach (var item in ParentMenuItems.OfType<MapLayerMenuItem>())
{
item.IsChecked = map.Children.Contains(item.MapLayer);
}
}
};
return map.Children.Contains(MapLayer);
}
public override async Task Execute(MapBase map)

View file

@ -1,6 +1,5 @@
using System;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
#if WPF
using System.Windows.Markup;
@ -26,28 +25,9 @@ namespace MapControl.UiTools
#endif
public string MapProjection { get; set; }
public MapProjectionMenuItem()
protected override bool GetIsChecked(MapBase map)
{
Loaded += (s, e) =>
{
if (DataContext is MapBase map)
{
IsChecked = map.MapProjection.CrsId == MapProjection;
}
};
Click += async (s, e) =>
{
if (DataContext is MapBase map)
{
await Execute(map);
foreach (var item in ParentMenuItems.OfType<MapProjectionMenuItem>())
{
item.IsChecked = map.MapProjection.CrsId == item.MapProjection;
}
}
};
return map.MapProjection.CrsId == MapProjection;
}
public override Task Execute(MapBase map)