mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-04-04 14:08:32 +00:00
Avalonia MapItemsControl
This commit is contained in:
parent
39e00b30d9
commit
e9e0393074
11 changed files with 206 additions and 68 deletions
|
|
@ -16,13 +16,13 @@ global using Avalonia.Media.Imaging;
|
|||
global using Avalonia.Platform;
|
||||
global using Avalonia.Styling;
|
||||
global using Avalonia.Threading;
|
||||
global using Brush = Avalonia.Media.IBrush;
|
||||
global using ImageSource = Avalonia.Media.IImage;
|
||||
global using DependencyObject = Avalonia.AvaloniaObject;
|
||||
global using DependencyProperty = Avalonia.AvaloniaProperty;
|
||||
global using FrameworkElement = Avalonia.Controls.Control;
|
||||
global using HorizontalAlignment = Avalonia.Layout.HorizontalAlignment;
|
||||
global using VerticalAlignment = Avalonia.Layout.VerticalAlignment;
|
||||
global using Brush = Avalonia.Media.IBrush;
|
||||
global using ImageSource = Avalonia.Media.IImage;
|
||||
global using PathFigureCollection = Avalonia.Media.PathFigures;
|
||||
global using PointCollection = System.Collections.Generic.List<Avalonia.Point>;
|
||||
global using PropertyPath = System.String;
|
||||
|
|
|
|||
|
|
@ -24,8 +24,6 @@
|
|||
<ItemGroup>
|
||||
<Compile Include="..\Shared\*.cs" />
|
||||
<Compile Remove="..\Shared\GeoImage.cs" />
|
||||
<Compile Remove="..\Shared\MapItem.cs" />
|
||||
<Compile Remove="..\Shared\MapItemsControl.cs" />
|
||||
<Compile Remove="..\Shared\ViewTransform.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
|
|
|
|||
24
MapControl/Avalonia/MapItem.Avalonia.cs
Normal file
24
MapControl/Avalonia/MapItem.Avalonia.cs
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
||||
// Copyright © 2024 Clemens Fischer
|
||||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
namespace MapControl
|
||||
{
|
||||
public partial class MapItem
|
||||
{
|
||||
public static readonly StyledProperty<bool> AutoCollapseProperty =
|
||||
DependencyPropertyHelper.AddOwner<MapItem, bool>(MapPanel.AutoCollapseProperty);
|
||||
|
||||
public static readonly StyledProperty<Location> LocationProperty =
|
||||
DependencyPropertyHelper.AddOwner<MapItem, Location>(MapPanel.LocationProperty, null,
|
||||
(item, oldValue, newValue) => item.UpdateMapTransform(newValue));
|
||||
|
||||
protected override void OnPointerPressed(PointerPressedEventArgs e)
|
||||
{
|
||||
base.OnPointerPressed(e);
|
||||
|
||||
(ItemsControl.ItemsControlFromItemContainer(this) as MapItemsControl)?.OnItemClicked(
|
||||
this, e.KeyModifiers.HasFlag(KeyModifiers.Control), e.KeyModifiers.HasFlag(KeyModifiers.Shift));
|
||||
}
|
||||
}
|
||||
}
|
||||
64
MapControl/Avalonia/MapItemsControl.Avalonia.cs
Normal file
64
MapControl/Avalonia/MapItemsControl.Avalonia.cs
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
|
||||
// Copyright © 2024 Clemens Fischer
|
||||
// Licensed under the Microsoft Public License (Ms-PL)
|
||||
|
||||
using Avalonia.Controls.Presenters;
|
||||
using Avalonia.Controls.Templates;
|
||||
|
||||
namespace MapControl
|
||||
{
|
||||
public partial class MapItemsControl
|
||||
{
|
||||
static MapItemsControl()
|
||||
{
|
||||
TemplateProperty.OverrideDefaultValue<MapItemsControl>(
|
||||
new FuncControlTemplate<MapItemsControl>(
|
||||
(itemsControl, namescope) => new ItemsPresenter { ItemsPanel = itemsControl.ItemsPanel }));
|
||||
|
||||
ItemsPanelProperty.OverrideDefaultValue<MapItemsControl>(
|
||||
new FuncTemplate<Panel>(() => new MapPanel()));
|
||||
}
|
||||
|
||||
public void SelectItemsInGeometry(Geometry geometry)
|
||||
{
|
||||
SelectItemsByPosition(p => geometry.FillContains(p));
|
||||
}
|
||||
|
||||
protected override bool NeedsContainerOverride(object item, int index, out object recycleKey)
|
||||
{
|
||||
recycleKey = null;
|
||||
|
||||
return item is not MapItem;
|
||||
}
|
||||
|
||||
protected override Control CreateContainerForItemOverride(object item, int index, object recycleKey)
|
||||
{
|
||||
return new MapItem();
|
||||
}
|
||||
|
||||
protected override void PrepareContainerForItemOverride(Control container, object item, int index)
|
||||
{
|
||||
base.PrepareContainerForItemOverride(container, item, index);
|
||||
|
||||
if (LocationMemberPath != null && container is MapItem mapItem)
|
||||
{
|
||||
mapItem.SetBinding(MapItem.LocationProperty,
|
||||
new Binding
|
||||
{
|
||||
Path = new PropertyPath(LocationMemberPath),
|
||||
Source = item
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
protected override void ClearContainerForItemOverride(Control container)
|
||||
{
|
||||
base.ClearContainerForItemOverride(container);
|
||||
|
||||
if (LocationMemberPath != null && container is MapItem mapItem)
|
||||
{
|
||||
mapItem.ClearValue(MapItem.LocationProperty);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -2,6 +2,24 @@
|
|||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:map="clr-namespace:MapControl">
|
||||
|
||||
<!-- Style replaced by TemplateProperty and ItemsPanelProperty default value overrides -->
|
||||
<!--
|
||||
<Style Selector="map|MapItemsControl">
|
||||
<Setter Property="Template">
|
||||
<ControlTemplate>
|
||||
<ItemsPresenter ItemsPanel="{TemplateBinding ItemsPanel}"/>
|
||||
</ControlTemplate>
|
||||
</Setter>
|
||||
<Setter Property="ItemsPanel">
|
||||
<Setter.Value>
|
||||
<ItemsPanelTemplate>
|
||||
<map:MapPanel/>
|
||||
</ItemsPanelTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
-->
|
||||
|
||||
<Style Selector="map|MapContentControl">
|
||||
<Setter Property="Background" Value="{Binding Background, RelativeSource={RelativeSource AncestorType=map:MapBase}}"/>
|
||||
<Setter Property="BorderBrush" Value="{Binding Foreground, RelativeSource={RelativeSource AncestorType=map:MapBase}}"/>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue