mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
51 lines
1.3 KiB
C#
51 lines
1.3 KiB
C#
|
|
using System.Threading.Tasks;
|
|||
|
|
#if WPF
|
|||
|
|
using System.Windows;
|
|||
|
|
using System.Windows.Controls;
|
|||
|
|
#elif UWP
|
|||
|
|
using Windows.UI.Xaml;
|
|||
|
|
using Windows.UI.Xaml.Controls;
|
|||
|
|
#elif WINUI
|
|||
|
|
using Microsoft.UI.Xaml;
|
|||
|
|
using Microsoft.UI.Xaml.Controls;
|
|||
|
|
#else
|
|||
|
|
using Avalonia.Controls;
|
|||
|
|
using DependencyProperty = Avalonia.AvaloniaProperty;
|
|||
|
|
#endif
|
|||
|
|
|
|||
|
|
namespace MapControl.UiTools
|
|||
|
|
{
|
|||
|
|
public partial class MenuButton : Button
|
|||
|
|
{
|
|||
|
|
public static readonly DependencyProperty MapProperty =
|
|||
|
|
DependencyPropertyHelper.Register<MenuButton, MapBase>(nameof(Map), null,
|
|||
|
|
async (button, oldValue, newValue) => await button.Initialize());
|
|||
|
|
|
|||
|
|
public MapBase Map
|
|||
|
|
{
|
|||
|
|
get => (MapBase)GetValue(MapProperty);
|
|||
|
|
set => SetValue(MapProperty, value);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private async Task Initialize()
|
|||
|
|
{
|
|||
|
|
if (Map != null)
|
|||
|
|
{
|
|||
|
|
DataContext = Map;
|
|||
|
|
|
|||
|
|
if (Items.Count > 0)
|
|||
|
|
{
|
|||
|
|
if (Items[0] is MapLayerMenuItem mapLayerItem)
|
|||
|
|
{
|
|||
|
|
await mapLayerItem.Execute(Map);
|
|||
|
|
}
|
|||
|
|
else if (Items[0] is MapProjectionMenuItem mapProjectionItem)
|
|||
|
|
{
|
|||
|
|
mapProjectionItem.Execute(Map);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|