mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
MapMenuItem
This commit is contained in:
parent
616b2bf3f7
commit
3f16d1d637
|
|
@ -1,7 +1,7 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net9.0-windows;net462</TargetFrameworks>
|
||||
<LangVersion Condition="'$(TargetFramework)'=='net462'">8.0</LangVersion>
|
||||
<LangVersion Condition="'$(TargetFramework)'=='net462'">12.0</LangVersion>
|
||||
<UseWPF>true</UseWPF>
|
||||
<DefineConstants>WPF</DefineConstants>
|
||||
<RootNamespace>MapControl.MBTiles</RootNamespace>
|
||||
|
|
|
|||
|
|
@ -4,16 +4,11 @@ using Avalonia.Media;
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MapControl.UiTools
|
||||
{
|
||||
public abstract partial class MapMenuItem : MenuItem
|
||||
{
|
||||
public abstract bool GetIsChecked(MapBase map);
|
||||
|
||||
public abstract Task ExecuteAsync(MapBase map);
|
||||
|
||||
protected MapMenuItem()
|
||||
{
|
||||
Icon = new TextBlock
|
||||
|
|
@ -23,26 +18,8 @@ namespace MapControl.UiTools
|
|||
VerticalAlignment = Avalonia.Layout.VerticalAlignment.Center,
|
||||
};
|
||||
|
||||
Loaded += (s, e) =>
|
||||
{
|
||||
if (DataContext is MapBase map)
|
||||
{
|
||||
IsChecked = GetIsChecked(map);
|
||||
}
|
||||
};
|
||||
|
||||
Click += async (s, e) =>
|
||||
{
|
||||
if (DataContext is MapBase map)
|
||||
{
|
||||
await ExecuteAsync(map);
|
||||
|
||||
foreach (var item in ParentMenuItems)
|
||||
{
|
||||
item.IsChecked = item.GetIsChecked(map);
|
||||
}
|
||||
}
|
||||
};
|
||||
Loaded += (s, e) => Initialize();
|
||||
Click += (s, e) => Execute();
|
||||
}
|
||||
|
||||
public string Text
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ namespace MapControl.UiTools
|
|||
#endif
|
||||
public FrameworkElement MapLayer { get; set; }
|
||||
|
||||
public override bool GetIsChecked(MapBase map)
|
||||
protected override bool GetIsChecked(MapBase map)
|
||||
{
|
||||
return MapLayer != null && map.Children.Contains(MapLayer);
|
||||
}
|
||||
|
|
|
|||
30
MapUiTools/Shared/MapMenuItem.cs
Normal file
30
MapUiTools/Shared/MapMenuItem.cs
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
using System.Threading.Tasks;
|
||||
|
||||
namespace MapControl.UiTools
|
||||
{
|
||||
public abstract partial class MapMenuItem
|
||||
{
|
||||
public abstract Task ExecuteAsync(MapBase map);
|
||||
|
||||
protected abstract bool GetIsChecked(MapBase map);
|
||||
|
||||
protected virtual bool GetIsEnabled(MapBase map) => true;
|
||||
|
||||
private void Initialize()
|
||||
{
|
||||
if (DataContext is MapBase map)
|
||||
{
|
||||
IsEnabled = GetIsEnabled(map);
|
||||
IsChecked = GetIsChecked(map);
|
||||
}
|
||||
}
|
||||
|
||||
private async void Execute()
|
||||
{
|
||||
if (DataContext is MapBase map)
|
||||
{
|
||||
await ExecuteAsync(map);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
#if WPF
|
||||
using System.Windows.Markup;
|
||||
|
|
@ -14,20 +15,25 @@ using Avalonia.Metadata;
|
|||
namespace MapControl.UiTools
|
||||
{
|
||||
#if WPF
|
||||
[ContentProperty(nameof(MapProjection))]
|
||||
[ContentProperty(nameof(CrsId))]
|
||||
#elif UWP || WINUI
|
||||
[ContentProperty(Name = nameof(MapProjection))]
|
||||
[ContentProperty(Name = nameof(CrsId))]
|
||||
#endif
|
||||
public partial class MapProjectionMenuItem : MapMenuItem
|
||||
{
|
||||
#if AVALONIA
|
||||
[Content]
|
||||
#endif
|
||||
public string MapProjection { get; set; }
|
||||
public string CrsId { get; set; }
|
||||
|
||||
public override bool GetIsChecked(MapBase map)
|
||||
protected override bool GetIsEnabled(MapBase map)
|
||||
{
|
||||
return map.MapProjection.ToString() == MapProjection;
|
||||
return map.MapLayer is not IMapLayer mapLayer || mapLayer.SupportedCrsIds.Contains(CrsId);
|
||||
}
|
||||
|
||||
protected override bool GetIsChecked(MapBase map)
|
||||
{
|
||||
return map.MapProjection.CrsId == CrsId;
|
||||
}
|
||||
|
||||
public override Task ExecuteAsync(MapBase map)
|
||||
|
|
@ -36,7 +42,7 @@ namespace MapControl.UiTools
|
|||
{
|
||||
try
|
||||
{
|
||||
map.MapProjection = MapControl.MapProjection.Parse(MapProjection);
|
||||
map.MapProjection = MapProjection.Parse(CrsId);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
<DefineConstants>UWP</DefineConstants>
|
||||
<RootNamespace>MapControl.UiTools</RootNamespace>
|
||||
<AssemblyTitle>XAML Map Control UI Tools Library for UWP</AssemblyTitle>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<DisableRuntimeMarshalling>true</DisableRuntimeMarshalling>
|
||||
<DefaultLanguage>en-US</DefaultLanguage>
|
||||
</PropertyGroup>
|
||||
|
|
|
|||
|
|
@ -1,38 +1,15 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace MapControl.UiTools
|
||||
{
|
||||
public abstract partial class MapMenuItem : MenuItem
|
||||
public partial class MapMenuItem : MenuItem
|
||||
{
|
||||
public abstract bool GetIsChecked(MapBase map);
|
||||
|
||||
public abstract Task ExecuteAsync(MapBase map);
|
||||
|
||||
protected MapMenuItem()
|
||||
{
|
||||
Loaded += (s, e) =>
|
||||
{
|
||||
if (DataContext is MapBase map)
|
||||
{
|
||||
IsChecked = GetIsChecked(map);
|
||||
}
|
||||
};
|
||||
|
||||
Click += async (s, e) =>
|
||||
{
|
||||
if (DataContext is MapBase map)
|
||||
{
|
||||
await ExecuteAsync(map);
|
||||
|
||||
foreach (var item in ParentMenuItems)
|
||||
{
|
||||
item.IsChecked = item.GetIsChecked(map);
|
||||
}
|
||||
}
|
||||
};
|
||||
Loaded += (s, e) => Initialize();
|
||||
Click += (s, e) => Execute();
|
||||
}
|
||||
|
||||
public string Text
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net9.0-windows;net462</TargetFrameworks>
|
||||
<LangVersion Condition="'$(TargetFramework)'=='net462'">8.0</LangVersion>
|
||||
<LangVersion Condition="'$(TargetFramework)'=='net462'">12.0</LangVersion>
|
||||
<UseWPF>true</UseWPF>
|
||||
<DefineConstants>WPF</DefineConstants>
|
||||
<RootNamespace>MapControl.UiTools</RootNamespace>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
#if UWP
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Windows.UI.Xaml.Media;
|
||||
|
|
@ -13,34 +12,15 @@ namespace MapControl.UiTools
|
|||
{
|
||||
public abstract partial class MapMenuItem : ToggleMenuFlyoutItem
|
||||
{
|
||||
public abstract bool GetIsChecked(MapBase map);
|
||||
|
||||
public abstract Task ExecuteAsync(MapBase map);
|
||||
|
||||
protected MapMenuItem()
|
||||
{
|
||||
Loaded += (s, e) =>
|
||||
{
|
||||
ParentMenuItems = ((Panel)VisualTreeHelper.GetParent(this)).Children.OfType<MapMenuItem>().ToList();
|
||||
|
||||
if (DataContext is MapBase map)
|
||||
{
|
||||
IsChecked = GetIsChecked(map);
|
||||
}
|
||||
Initialize();
|
||||
};
|
||||
|
||||
Click += async (s, e) =>
|
||||
{
|
||||
if (DataContext is MapBase map)
|
||||
{
|
||||
await ExecuteAsync(map);
|
||||
|
||||
foreach (var item in ParentMenuItems)
|
||||
{
|
||||
item.IsChecked = item.GetIsChecked(map);
|
||||
}
|
||||
}
|
||||
};
|
||||
Click += (s, e) => Execute();
|
||||
}
|
||||
|
||||
protected IList<MapMenuItem> ParentMenuItems { get; private set; }
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
<DefineConstants>WINUI</DefineConstants>
|
||||
<RootNamespace>MapControl.UiTools</RootNamespace>
|
||||
<AssemblyTitle>XAML Map Control UI Tools Library for WinUI</AssemblyTitle>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
|||
Loading…
Reference in a new issue