Added MapUiTools.Avalonia

This commit is contained in:
ClemensFischer 2024-05-24 15:15:29 +02:00
parent 197f004eeb
commit 57758ed975
10 changed files with 182 additions and 31 deletions

View file

@ -25,10 +25,10 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="System.Data.SQLite.Core" Version="1.0.118" />
<ProjectReference Include="..\..\MapControl\WPF\MapControl.WPF.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\MapControl\WPF\MapControl.WPF.csproj" />
<PackageReference Include="System.Data.SQLite.Core" Version="1.0.118" />
</ItemGroup>
</Project>

View file

@ -26,13 +26,13 @@
<Compile Include="..\Shared\*.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\MapControl\WinUI\MapControl.WinUI.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.240428000" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.26100.1" />
<PackageReference Include="System.Data.SQLite.Core" Version="1.0.118" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\MapControl\WinUI\MapControl.WinUI.csproj" />
</ItemGroup>
</Project>

View file

@ -29,10 +29,10 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="ProjNET4GeoAPI" Version="1.4.1" />
<ProjectReference Include="..\..\MapControl\WPF\MapControl.WPF.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\MapControl\WPF\MapControl.WPF.csproj" />
<PackageReference Include="ProjNET4GeoAPI" Version="1.4.1" />
</ItemGroup>
</Project>

View file

@ -26,13 +26,13 @@
<Compile Include="..\Shared\*.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\MapControl\WinUI\MapControl.WinUI.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.240428000" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.26100.1" />
<PackageReference Include="ProjNET4GeoAPI" Version="1.4.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\MapControl\WinUI\MapControl.WinUI.csproj" />
</ItemGroup>
</Project>

View file

@ -0,0 +1,33 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>disable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<RootNamespace>MapControl</RootNamespace>
<AssemblyTitle>XAML Map Control UI Tools Library for WPF</AssemblyTitle>
<Product>XAML Map Control</Product>
<Version>10.0.0</Version>
<Authors>Clemens Fischer</Authors>
<Copyright>Copyright © 2024 Clemens Fischer</Copyright>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\MapControl.snk</AssemblyOriginatorKeyFile>
<DelaySign>false</DelaySign>
<DefineConstants>AVALONIA</DefineConstants>
</PropertyGroup>
<ItemGroup>
<None Include="..\..\MapControl.snk" Link="MapControl.snk" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\Shared\*.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\MapControl\Avalonia\MapControl.Avalonia.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="11.0.10" />
</ItemGroup>
</Project>

View file

@ -0,0 +1,93 @@
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
// Copyright © 2024 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using Avalonia;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Media;
using Avalonia.Styling;
using System;
using System.Collections.Generic;
using System.Linq;
namespace MapControl
{
public class ToggleMenuFlyoutItem : MenuItem
{
internal static readonly FontFamily SymbolFont = new FontFamily("Segoe MDL2 Assets");
private readonly StackPanel header;
private readonly TextBlock icon;
private bool isChecked;
public ToggleMenuFlyoutItem(string text, object item, EventHandler<RoutedEventArgs> click)
{
icon = new TextBlock
{
FontFamily = SymbolFont,
Width = 20,
VerticalAlignment = Avalonia.Layout.VerticalAlignment.Center
};
header = new StackPanel { Orientation = Avalonia.Layout.Orientation.Horizontal };
header.Children.Add(icon);
header.Children.Add(new TextBlock { Text = text });
Header = header;
Tag = item;
Click += click;
}
protected override Type StyleKeyOverride => typeof(MenuItem);
public bool IsChecked
{
get => isChecked;
set
{
isChecked = value;
icon.Text = isChecked ? "\uE73E" : ""; // CheckMark
}
}
}
public class MenuButton : Button
{
protected MenuButton(string icon)
{
var style = new Style();
style.Setters.Add(new Setter(TextBlock.FontFamilyProperty, ToggleMenuFlyoutItem.SymbolFont));
style.Setters.Add(new Setter(TextBlock.FontSizeProperty, 20d));
style.Setters.Add(new Setter(PaddingProperty, new Thickness(8)));
Styles.Add(style);
Content = icon;
}
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();
}
}
}

View file

@ -15,32 +15,42 @@ using Windows.UI.Xaml.Markup;
#elif WINUI
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Markup;
#elif AVALONIA
using Avalonia.Interactivity;
using Avalonia.Metadata;
using DependencyProperty = Avalonia.AvaloniaProperty;
using FrameworkElement = Avalonia.Controls.Control;
#endif
namespace MapControl.UiTools
{
#if WPF
[ContentProperty(nameof(Layer))]
#else
#elif UWP || WINUI
[ContentProperty(Name = nameof(Layer))]
#endif
public class MapLayerItem
{
public string Text { get; set; }
public UIElement Layer { get; set; }
public Func<UIElement> LayerFactory { get; set; }
#if AVALONIA
[Content]
#endif
public FrameworkElement Layer { get; set; }
public UIElement GetLayer() => Layer ?? (Layer = LayerFactory?.Invoke());
public string Text { get; set; }
public Func<FrameworkElement> LayerFactory { get; set; }
public FrameworkElement GetLayer() => Layer ?? (Layer = LayerFactory?.Invoke());
}
#if WPF
[ContentProperty(nameof(MapLayers))]
#else
#elif UWP || WINUI
[ContentProperty(Name = nameof(MapLayers))]
#endif
public class MapLayersMenuButton : MenuButton
{
private UIElement selectedLayer;
private FrameworkElement selectedLayer;
public MapLayersMenuButton()
: base("\uE81E")
@ -59,6 +69,9 @@ namespace MapControl.UiTools
set => SetValue(MapProperty, value);
}
#if AVALONIA
[Content]
#endif
public Collection<MapLayerItem> MapLayers { get; } = new ObservableCollection<MapLayerItem>();
public Collection<MapLayerItem> MapOverlays { get; } = new ObservableCollection<MapLayerItem>();
@ -112,7 +125,7 @@ namespace MapControl.UiTools
ToggleMapOverlay(mapLayerItem.GetLayer());
}
private void SetMapLayer(UIElement layer)
private void SetMapLayer(FrameworkElement layer)
{
if (selectedLayer != layer)
{
@ -123,7 +136,7 @@ namespace MapControl.UiTools
UpdateCheckedStates();
}
private void ToggleMapOverlay(UIElement layer)
private void ToggleMapOverlay(FrameworkElement layer)
{
if (Map.Children.Contains(layer))
{

View file

@ -14,24 +14,33 @@ using Windows.UI.Xaml.Markup;
#elif WINUI
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Markup;
#elif AVALONIA
using Avalonia.Interactivity;
using Avalonia.Metadata;
using DependencyProperty = Avalonia.AvaloniaProperty;
using FrameworkElement = Avalonia.Controls.Control;
#endif
namespace MapControl.UiTools
{
#if WPF
[ContentProperty(nameof(Projection))]
#else
#elif UWP || WINUI
[ContentProperty(Name = nameof(Projection))]
#endif
public class MapProjectionItem
{
public string Text { get; set; }
#if AVALONIA
[Content]
#endif
public string Projection { get; set; }
public string Text { get; set; }
}
#if WPF
[ContentProperty(nameof(MapProjections))]
#else
#elif UWP || WINUI
[ContentProperty(Name = nameof(MapProjections))]
#endif
public class MapProjectionsMenuButton : MenuButton
@ -54,6 +63,9 @@ namespace MapControl.UiTools
set => SetValue(MapProperty, value);
}
#if AVALONIA
[Content]
#endif
public Collection<MapProjectionItem> MapProjections { get; } = new ObservableCollection<MapProjectionItem>();
private void InitializeMenu()

View file

@ -25,11 +25,11 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.240428000" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.26100.1" />
<ProjectReference Include="..\..\MapControl\WinUI\MapControl.WinUI.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\MapControl\WinUI\MapControl.WinUI.csproj" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.240428000" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.26100.1" />
</ItemGroup>
</Project>

View file

@ -4,12 +4,12 @@
using System.Collections.Generic;
using System.Linq;
#if WINUI
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
#elif UWP
#if UWP
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
#elif WINUI
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
#endif
namespace MapControl.UiTools