mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2025-12-06 07:12:04 +01:00
MapItemsControl SelectionMode
This commit is contained in:
parent
c4c5d2d1df
commit
5a738f7a71
|
|
@ -15,8 +15,8 @@ namespace MapControl
|
|||
|
||||
protected override void OnPointerPressed(PointerPressedEventArgs e)
|
||||
{
|
||||
(ItemsControl.ItemsControlFromItemContainer(this) as MapItemsControl)?.OnItemClicked(
|
||||
this, e.KeyModifiers.HasFlag(KeyModifiers.Control), e.KeyModifiers.HasFlag(KeyModifiers.Shift));
|
||||
(ItemsControl.ItemsControlFromItemContainer(this) as MapItemsControl)?
|
||||
.OnItemClicked(this, e.KeyModifiers.HasFlag(KeyModifiers.Control));
|
||||
|
||||
e.Handled = true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -82,14 +82,12 @@ namespace MapControl
|
|||
SelectItemsByPosition(p => rect.Contains(p));
|
||||
}
|
||||
|
||||
protected internal void OnItemClicked(MapItem mapItem, bool controlKey, bool shiftKey)
|
||||
protected internal void OnItemClicked(MapItem mapItem, bool controlKey)
|
||||
{
|
||||
var item = ItemFromContainer(mapItem);
|
||||
|
||||
if (SelectionMode == SelectionMode.Single)
|
||||
if (SelectionMode == SelectionMode.Single) // set SelectedItem
|
||||
{
|
||||
// Single -> set only SelectedItem.
|
||||
|
||||
if (SelectedItem != item)
|
||||
{
|
||||
SelectedItem = item;
|
||||
|
|
@ -99,10 +97,8 @@ namespace MapControl
|
|||
SelectedItem = null;
|
||||
}
|
||||
}
|
||||
else if (SelectionMode == SelectionMode.Multiple || controlKey)
|
||||
else if (controlKey) // toggle item in SelectedItems
|
||||
{
|
||||
// Multiple or Extended with Ctrl -> toggle item in SelectedItems.
|
||||
|
||||
if (SelectedItems.Contains(item))
|
||||
{
|
||||
SelectedItems.Remove(item);
|
||||
|
|
@ -112,23 +108,10 @@ namespace MapControl
|
|||
SelectedItems.Add(item);
|
||||
}
|
||||
}
|
||||
else if (shiftKey && SelectedItem != null)
|
||||
else // set single item in SelectedItems
|
||||
{
|
||||
// Extended with Shift -> select items in view rectangle.
|
||||
|
||||
var p1 = MapPanel.GetViewPosition(ContainerFromItem(SelectedItem));
|
||||
var p2 = MapPanel.GetViewPosition(mapItem);
|
||||
|
||||
if (p1.HasValue && p2.HasValue)
|
||||
{
|
||||
SelectItemsInRect(new Rect(p1.Value, p2.Value));
|
||||
}
|
||||
}
|
||||
else if (SelectedItem != item)
|
||||
{
|
||||
// Extended without Control or Shift -> set selected item.
|
||||
|
||||
SelectedItem = item;
|
||||
SelectedItems.Clear();
|
||||
SelectedItems.Add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,8 +24,8 @@ namespace MapControl
|
|||
|
||||
protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
|
||||
{
|
||||
(ItemsControl.ItemsControlFromItemContainer(this) as MapItemsControl)?.OnItemClicked(
|
||||
this, Keyboard.Modifiers.HasFlag(ModifierKeys.Control), Keyboard.Modifiers.HasFlag(ModifierKeys.Shift));
|
||||
(ItemsControl.ItemsControlFromItemContainer(this) as MapItemsControl)?
|
||||
.OnItemClicked(this, Keyboard.Modifiers.HasFlag(ModifierKeys.Control));
|
||||
|
||||
e.Handled = true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,8 +39,8 @@ namespace MapControl
|
|||
|
||||
protected override void OnPointerPressed(PointerRoutedEventArgs e)
|
||||
{
|
||||
(ItemsControl.ItemsControlFromItemContainer(this) as MapItemsControl)?.OnItemClicked(
|
||||
this, e.KeyModifiers.HasFlag(VirtualKeyModifiers.Control), e.KeyModifiers.HasFlag(VirtualKeyModifiers.Shift));
|
||||
(ItemsControl.ItemsControlFromItemContainer(this) as MapItemsControl)?
|
||||
.OnItemClicked(this, e.KeyModifiers.HasFlag(VirtualKeyModifiers.Control));
|
||||
|
||||
e.Handled = true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
ManipulationModes="All"
|
||||
DoubleTapped="OnMapDoubleTapped">
|
||||
|
||||
<map:MapItemsControl ItemsSource="{Binding Pushpins}" SelectionMode="Multiple">
|
||||
<map:MapItemsControl ItemsSource="{Binding Pushpins}">
|
||||
<map:MapItemsControl.Styles>
|
||||
<Style Selector="map|MapItem">
|
||||
<Setter Property="map:MapPanel.Location" Value="{Binding Location}"/>
|
||||
|
|
|
|||
|
|
@ -168,7 +168,7 @@
|
|||
<map:MapItemsControl ItemsSource="{Binding Points}"
|
||||
ItemContainerStyle="{StaticResource PointItemStyle}"
|
||||
LocationMemberPath="Location"
|
||||
SelectionMode="Extended"/>
|
||||
SelectionMode="Multiple"/>
|
||||
|
||||
<map:MapItemsControl ItemsSource="{Binding Pushpins}"
|
||||
ItemContainerStyle="{StaticResource PushpinItemStyle}"
|
||||
|
|
|
|||
|
|
@ -132,7 +132,7 @@
|
|||
|
||||
<map:MapItemsControl ItemsSource="{Binding Points}"
|
||||
ItemContainerStyle="{StaticResource PointItemStyle}"
|
||||
SelectionMode="Extended"/>
|
||||
SelectionMode="Multiple"/>
|
||||
|
||||
<map:MapItemsControl ItemsSource="{Binding Pushpins}"
|
||||
ItemContainerStyle="{StaticResource PushpinItemStyle}"/>
|
||||
|
|
|
|||
Loading…
Reference in a new issue