mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
Range selection in MapItemsControl
This commit is contained in:
parent
da63e55fd4
commit
1fc35d90c0
|
|
@ -9,14 +9,12 @@
|
||||||
DependencyPropertyHelper.AddOwner<MapItem, Location>(MapPanel.LocationProperty, null,
|
DependencyPropertyHelper.AddOwner<MapItem, Location>(MapPanel.LocationProperty, null,
|
||||||
(item, oldValue, newValue) => item.UpdateMapTransform(newValue));
|
(item, oldValue, newValue) => item.UpdateMapTransform(newValue));
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Prevent range selection by Shift+PointerPressed.
|
|
||||||
/// </summary>
|
|
||||||
protected override void OnPointerPressed(PointerPressedEventArgs e)
|
protected override void OnPointerPressed(PointerPressedEventArgs e)
|
||||||
{
|
{
|
||||||
if (e.KeyModifiers.HasFlag(KeyModifiers.Shift))
|
if (e.KeyModifiers.HasFlag(KeyModifiers.Shift))
|
||||||
{
|
{
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
|
MapItemsControl.SetSelectedItemsRange(this);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -78,5 +78,42 @@ namespace MapControl
|
||||||
{
|
{
|
||||||
SelectItemsByPosition(rect.Contains);
|
SelectItemsByPosition(rect.Contains);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static void SetSelectedItemsRange(MapItem mapItem)
|
||||||
|
{
|
||||||
|
if (ItemsControlFromItemContainer(mapItem) is MapItemsControl mapItemsControl &&
|
||||||
|
mapItemsControl.SelectionMode != SelectionMode.Single)
|
||||||
|
{
|
||||||
|
var pos = MapPanel.GetViewPosition(mapItem);
|
||||||
|
|
||||||
|
if (pos.HasValue)
|
||||||
|
{
|
||||||
|
var xMin = pos.Value.X;
|
||||||
|
var xMax = pos.Value.X;
|
||||||
|
var yMin = pos.Value.Y;
|
||||||
|
var yMax = pos.Value.Y;
|
||||||
|
|
||||||
|
if (mapItemsControl.SelectedItem != null)
|
||||||
|
{
|
||||||
|
var selectedMapItem = mapItemsControl.ContainerFromItem(mapItemsControl.SelectedItem);
|
||||||
|
|
||||||
|
if (selectedMapItem != mapItem)
|
||||||
|
{
|
||||||
|
pos = MapPanel.GetViewPosition(selectedMapItem);
|
||||||
|
|
||||||
|
if (pos.HasValue)
|
||||||
|
{
|
||||||
|
xMin = Math.Min(xMin, pos.Value.X);
|
||||||
|
xMax = Math.Max(xMax, pos.Value.X);
|
||||||
|
yMin = Math.Min(yMin, pos.Value.Y);
|
||||||
|
yMax = Math.Max(yMax, pos.Value.Y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mapItemsControl.SelectItemsInRect(new Rect(xMin, yMin, xMax - xMin, yMax - yMin));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
|
using System.Windows.Controls;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
|
|
||||||
namespace MapControl
|
namespace MapControl
|
||||||
|
|
@ -17,14 +18,12 @@ namespace MapControl
|
||||||
DefaultStyleKeyProperty.OverrideMetadata(typeof(MapItem), new FrameworkPropertyMetadata(typeof(MapItem)));
|
DefaultStyleKeyProperty.OverrideMetadata(typeof(MapItem), new FrameworkPropertyMetadata(typeof(MapItem)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Prevent range selection by Shift+MouseLeftButtonDown.
|
|
||||||
/// </summary>
|
|
||||||
protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
|
protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
|
||||||
{
|
{
|
||||||
if (Keyboard.Modifiers.HasFlag(ModifierKeys.Shift))
|
if (Keyboard.Modifiers.HasFlag(ModifierKeys.Shift))
|
||||||
{
|
{
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
|
MapItemsControl.SetSelectedItemsRange(this);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -31,14 +31,12 @@ namespace MapControl
|
||||||
MapPanel.InitMapElement(this);
|
MapPanel.InitMapElement(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Prevent range selection by Shift+PointerPressed.
|
|
||||||
/// </summary>
|
|
||||||
protected override void OnPointerPressed(PointerRoutedEventArgs e)
|
protected override void OnPointerPressed(PointerRoutedEventArgs e)
|
||||||
{
|
{
|
||||||
if (e.KeyModifiers.HasFlag(VirtualKeyModifiers.Shift))
|
if (e.KeyModifiers.HasFlag(VirtualKeyModifiers.Shift))
|
||||||
{
|
{
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
|
MapItemsControl.SetSelectedItemsRange(this);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue