Selection in MapItemsControl

This commit is contained in:
ClemensF 2018-11-13 21:35:48 +01:00
parent ec13ed260d
commit d296600b9e
6 changed files with 194 additions and 17 deletions

View file

@ -180,6 +180,7 @@
<Compile Include="Map.WPF.cs" />
<Compile Include="MapBase.WPF.cs" />
<Compile Include="MapGraticule.WPF.cs" />
<Compile Include="MapItemsControl.WPF.cs" />
<Compile Include="MapMultiPolygon.WPF.cs" />
<Compile Include="MapOverlay.WPF.cs" />
<Compile Include="MapPanel.WPF.cs" />

View file

@ -0,0 +1,49 @@
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
// © 2018 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
namespace MapControl
{
/// <summary>
/// Container class for an item in a MapItemsControl.
/// </summary>
public class MapItem : ListBoxItem
{
public MapItem()
{
DefaultStyleKey = typeof(MapItem);
MapPanel.InitMapElement(this);
}
protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
{
e.Handled = true;
(ItemsControl.ItemsControlFromItemContainer(this) as MapItemsControl)?.MapItemClicked(
this, Keyboard.Modifiers.HasFlag(ModifierKeys.Control), Keyboard.Modifiers.HasFlag(ModifierKeys.Shift));
}
}
public partial class MapItemsControl
{
public MapItem MapItemFromItem(object item)
{
return (MapItem)ItemContainerGenerator.ContainerFromItem(item);
}
public object ItemFromMapItem(MapItem mapItem)
{
return ItemContainerGenerator.ItemFromContainer(mapItem);
}
public void SelectItemsInGeometry(Geometry geometry)
{
SelectItemsByPosition(p => geometry.FillContains(p));
}
}
}

View file

@ -18,7 +18,7 @@
</Setter>
</Style>
<Style TargetType="map:MapItem">
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
<Setter Property="Focusable" Value="False"/>
<Setter Property="HorizontalAlignment" Value="Stretch"/>
<Setter Property="VerticalAlignment" Value="Stretch"/>
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>