mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-04-06 06:55:04 +00:00
Reworked sample applications
This commit is contained in:
parent
e2f4fc13b1
commit
1d1b2942b4
9 changed files with 468 additions and 283 deletions
|
|
@ -2,57 +2,70 @@
|
|||
// © 2022 Clemens Fischer
|
||||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.Specialized;
|
||||
using System.Linq;
|
||||
#if WINUI
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Markup;
|
||||
#elif UWP
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Markup;
|
||||
#else
|
||||
using System.Windows;
|
||||
using System.Windows.Markup;
|
||||
#endif
|
||||
|
||||
namespace MapControl.UiTools
|
||||
{
|
||||
#if WINUI || UWP
|
||||
[ContentProperty(Name = nameof(Projection))]
|
||||
#else
|
||||
[ContentProperty(nameof(Projection))]
|
||||
#endif
|
||||
public class MapProjectionItem
|
||||
{
|
||||
public string Text { get; set; }
|
||||
public MapProjection Projection { get; set; }
|
||||
}
|
||||
|
||||
#if WINUI || UWP
|
||||
[ContentProperty(Name = nameof(MapProjections))]
|
||||
#else
|
||||
[ContentProperty(nameof(MapProjections))]
|
||||
#endif
|
||||
public class MapProjectionsMenuButton : MenuButton
|
||||
{
|
||||
public MapProjectionsMenuButton()
|
||||
: base("\uE809")
|
||||
{
|
||||
((INotifyCollectionChanged)MapProjections).CollectionChanged += (s, e) => InitializeMenu();
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty MapProperty = DependencyProperty.Register(
|
||||
nameof(Map), typeof(MapBase), typeof(MapProjectionsMenuButton),
|
||||
new PropertyMetadata(null, (o, e) => ((MapProjectionsMenuButton)o).InitializeMenu()));
|
||||
|
||||
public static readonly DependencyProperty MapProjectionsProperty = DependencyProperty.Register(
|
||||
nameof(MapProjections), typeof(IDictionary<string, MapProjection>), typeof(MapProjectionsMenuButton),
|
||||
new PropertyMetadata(null, (o, e) => ((MapProjectionsMenuButton)o).InitializeMenu()));
|
||||
|
||||
public MapBase Map
|
||||
{
|
||||
get { return (MapBase)GetValue(MapProperty); }
|
||||
set { SetValue(MapProperty, value); }
|
||||
}
|
||||
|
||||
public IDictionary<string, MapProjection> MapProjections
|
||||
{
|
||||
get { return (IDictionary<string, MapProjection>)GetValue(MapProjectionsProperty); }
|
||||
set { SetValue(MapProjectionsProperty, value); }
|
||||
}
|
||||
public Collection<MapProjectionItem> MapProjections { get; } = new ObservableCollection<MapProjectionItem>();
|
||||
|
||||
private void InitializeMenu()
|
||||
{
|
||||
if (Map != null && MapProjections != null)
|
||||
if (Map != null)
|
||||
{
|
||||
var menu = CreateMenu();
|
||||
|
||||
foreach (var projection in MapProjections)
|
||||
foreach (var item in MapProjections)
|
||||
{
|
||||
menu.Items.Add(CreateMenuItem(projection.Key, projection.Value, MapProjectionClicked));
|
||||
menu.Items.Add(CreateMenuItem(item.Text, item.Projection, MapProjectionClicked));
|
||||
}
|
||||
|
||||
var initialProjection = MapProjections.Values.FirstOrDefault();
|
||||
var initialProjection = MapProjections.Select(p => p.Projection).FirstOrDefault();
|
||||
|
||||
if (initialProjection != null)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue