MapItemsControl SelectedItem

This commit is contained in:
ClemensFischer 2024-05-31 00:08:41 +02:00
parent ec13e13af7
commit 1aa233bc79
4 changed files with 36 additions and 15 deletions

View file

@ -17,6 +17,8 @@
DoubleTapped="OnMapDoubleTapped">
<map:MapItemsControl ItemsSource="{Binding Pushpins}"
SelectedItem="{Binding SelectedPushpin}"
SelectionMode="Multiple"
DoubleTapped="OnMapItemsControlDoubleTapped">
<map:MapItemsControl.Styles>
<Style Selector="map|MapItem">
@ -29,7 +31,7 @@
</ControlTemplate>
</Setter>
</Style>
<Style Selector="map|MapItem[IsSelected=True]">
<Style Selector="map|MapItem:selected">
<Setter Property="Foreground" Value="OrangeRed"/>
</Style>
</map:MapItemsControl.Styles>

View file

@ -1,12 +1,12 @@
using MapControl;
using System.Collections.Generic;
using System.Diagnostics;
namespace SampleApplication
{
public class PointItem
{
public string Name { get; set; }
public Location Location { get; set; }
}
@ -21,6 +21,18 @@ namespace SampleApplication
public List<PointItem> Pushpins { get; } = new List<PointItem>();
public List<PolylineItem> Polylines { get; } = new List<PolylineItem>();
private PointItem selectedPushpin;
public PointItem SelectedPushpin
{
get => selectedPushpin;
set
{
selectedPushpin = value;
Debug.WriteLine(selectedPushpin?.Name);
}
}
public MapViewModel()
{
Points.Add(new PointItem
@ -62,7 +74,7 @@ namespace SampleApplication
Pushpins.Add(new PointItem
{
Name = "WHV - Eckwarderhörne",
Location = new Location(53.5495, 8.1877)
Location = new Location(53.5495, 8.1877),
});
Pushpins.Add(new PointItem
@ -83,6 +95,8 @@ namespace SampleApplication
Location = new Location(53.5207, 8.2323)
});
SelectedPushpin = Pushpins[0];
Polylines.Add(new PolylineItem
{
Locations = LocationCollection.Parse("53.5140,8.1451 53.5123,8.1506 53.5156,8.1623 53.5276,8.1757 53.5491,8.1852 53.5495,8.1877 53.5426,8.1993 53.5184,8.2219 53.5182,8.2386 53.5195,8.2387")

View file

@ -131,6 +131,7 @@
</VisualStateManager.VisualStateGroups>
<map:Pushpin x:Name="pushpin" Content="{Binding Name}"
Foreground="{TemplateBinding Foreground}"
HorizontalAlignment="{TemplateBinding HorizontalAlignment}"/>
</Grid>
</ControlTemplate>
@ -162,16 +163,18 @@
Stroke="{Binding Foreground, ElementName=map}"
StrokeThickness="2" StrokeDashArray="1,1"/>
<map:MapItemsControl ItemsSource="{Binding Polylines}"
ItemTemplate="{StaticResource PolylineItemTemplate}"/>
<map:MapItemsControl ItemTemplate="{StaticResource PolylineItemTemplate}"
ItemsSource="{Binding Polylines}"/>
<map:MapItemsControl ItemsSource="{Binding Points}"
ItemContainerStyle="{StaticResource PointItemStyle}"
LocationMemberPath="Location"
SelectionMode="Multiple"/>
<map:MapItemsControl ItemContainerStyle="{StaticResource PointItemStyle}"
ItemsSource="{Binding Points}"
SelectionMode="Multiple"
LocationMemberPath="Location"/>
<map:MapItemsControl ItemsSource="{Binding Pushpins}"
ItemContainerStyle="{StaticResource PushpinItemStyle}"
<map:MapItemsControl ItemContainerStyle="{StaticResource PushpinItemStyle}"
ItemsSource="{Binding Pushpins}"
SelectedItem="{Binding SelectedPushpin, Mode=TwoWay}"
SelectionMode="Multiple"
LocationMemberPath="Location"/>
<map:MapPath Location="53.5,8.2" Stroke="Blue" StrokeThickness="3" Fill="#1F007F00">

View file

@ -130,12 +130,14 @@
<map:MapItemsControl ItemsSource="{Binding Polylines}"/>
<map:MapItemsControl ItemsSource="{Binding Points}"
ItemContainerStyle="{StaticResource PointItemStyle}"
<map:MapItemsControl ItemContainerStyle="{StaticResource PointItemStyle}"
ItemsSource="{Binding Points}"
SelectionMode="Multiple"/>
<map:MapItemsControl ItemsSource="{Binding Pushpins}"
ItemContainerStyle="{StaticResource PushpinItemStyle}"/>
<map:MapItemsControl ItemContainerStyle="{StaticResource PushpinItemStyle}"
ItemsSource="{Binding Pushpins}"
SelectedItem="{Binding SelectedPushpin}"
SelectionMode="Multiple"/>
<map:Pushpin AutoCollapse="True" Location="65,-18" Content="Iceland"/>
<map:Pushpin AutoCollapse="True" Location="71,25" Content="Norway"/>