Fixed menu button selection

This commit is contained in:
Clemens 2022-01-21 18:37:05 +01:00
parent be0e06f581
commit 9a26fdaefc
2 changed files with 22 additions and 3 deletions

View file

@ -36,6 +36,8 @@ namespace MapControl.UiTools
#endif
public class MapLayersMenuButton : MenuButton
{
private UIElement selectedLayer;
public MapLayersMenuButton()
: base("\uE81E")
{
@ -108,7 +110,11 @@ namespace MapControl.UiTools
private void SetMapLayer(UIElement layer)
{
Map.MapLayer = layer;
if (selectedLayer != layer)
{
selectedLayer = layer;
Map.MapLayer = selectedLayer;
}
UpdateCheckedStates();
}

View file

@ -4,6 +4,7 @@
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Diagnostics;
using System.Linq;
#if WINUI
using Microsoft.UI.Xaml;
@ -13,6 +14,7 @@ using Windows.UI.Xaml;
using Windows.UI.Xaml.Markup;
#else
using System.Windows;
using System.Windows.Controls;
using System.Windows.Markup;
#endif
@ -36,6 +38,8 @@ namespace MapControl.UiTools
#endif
public class MapProjectionsMenuButton : MenuButton
{
private string selectedProjection;
public MapProjectionsMenuButton()
: base("\uE809")
{
@ -84,11 +88,20 @@ namespace MapControl.UiTools
private void SetMapProjection(string projection)
{
Map.MapProjection = MapProjection.Factory.CreateProjection(projection);
if (selectedProjection != projection)
{
selectedProjection = projection;
Map.MapProjection = MapProjection.Factory.CreateProjection(selectedProjection);
}
UpdateCheckedStates();
}
private void UpdateCheckedStates()
{
foreach (var item in GetMenuItems())
{
item.IsChecked = projection == (string)item.Tag;
item.IsChecked = selectedProjection == (string)item.Tag;
}
}
}