mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-04-07 15:36:20 +00:00
Avalonia MapItemsControl
This commit is contained in:
parent
39e00b30d9
commit
e9e0393074
11 changed files with 206 additions and 68 deletions
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue