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

View file

@ -1,12 +1,12 @@
using MapControl; using MapControl;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
namespace SampleApplication namespace SampleApplication
{ {
public class PointItem public class PointItem
{ {
public string Name { get; set; } public string Name { get; set; }
public Location Location { get; set; } public Location Location { get; set; }
} }
@ -21,6 +21,18 @@ namespace SampleApplication
public List<PointItem> Pushpins { get; } = new List<PointItem>(); public List<PointItem> Pushpins { get; } = new List<PointItem>();
public List<PolylineItem> Polylines { get; } = new List<PolylineItem>(); 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() public MapViewModel()
{ {
Points.Add(new PointItem Points.Add(new PointItem
@ -62,7 +74,7 @@ namespace SampleApplication
Pushpins.Add(new PointItem Pushpins.Add(new PointItem
{ {
Name = "WHV - Eckwarderhörne", Name = "WHV - Eckwarderhörne",
Location = new Location(53.5495, 8.1877) Location = new Location(53.5495, 8.1877),
}); });
Pushpins.Add(new PointItem Pushpins.Add(new PointItem
@ -83,6 +95,8 @@ namespace SampleApplication
Location = new Location(53.5207, 8.2323) Location = new Location(53.5207, 8.2323)
}); });
SelectedPushpin = Pushpins[0];
Polylines.Add(new PolylineItem 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") 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> </VisualStateManager.VisualStateGroups>
<map:Pushpin x:Name="pushpin" Content="{Binding Name}" <map:Pushpin x:Name="pushpin" Content="{Binding Name}"
Foreground="{TemplateBinding Foreground}"
HorizontalAlignment="{TemplateBinding HorizontalAlignment}"/> HorizontalAlignment="{TemplateBinding HorizontalAlignment}"/>
</Grid> </Grid>
</ControlTemplate> </ControlTemplate>
@ -162,16 +163,18 @@
Stroke="{Binding Foreground, ElementName=map}" Stroke="{Binding Foreground, ElementName=map}"
StrokeThickness="2" StrokeDashArray="1,1"/> StrokeThickness="2" StrokeDashArray="1,1"/>
<map:MapItemsControl ItemsSource="{Binding Polylines}" <map:MapItemsControl ItemTemplate="{StaticResource PolylineItemTemplate}"
ItemTemplate="{StaticResource PolylineItemTemplate}"/> ItemsSource="{Binding Polylines}"/>
<map:MapItemsControl ItemsSource="{Binding Points}" <map:MapItemsControl ItemContainerStyle="{StaticResource PointItemStyle}"
ItemContainerStyle="{StaticResource PointItemStyle}" ItemsSource="{Binding Points}"
LocationMemberPath="Location" SelectionMode="Multiple"
SelectionMode="Multiple"/> LocationMemberPath="Location"/>
<map:MapItemsControl ItemsSource="{Binding Pushpins}" <map:MapItemsControl ItemContainerStyle="{StaticResource PushpinItemStyle}"
ItemContainerStyle="{StaticResource PushpinItemStyle}" ItemsSource="{Binding Pushpins}"
SelectedItem="{Binding SelectedPushpin, Mode=TwoWay}"
SelectionMode="Multiple"
LocationMemberPath="Location"/> LocationMemberPath="Location"/>
<map:MapPath Location="53.5,8.2" Stroke="Blue" StrokeThickness="3" Fill="#1F007F00"> <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 Polylines}"/>
<map:MapItemsControl ItemsSource="{Binding Points}" <map:MapItemsControl ItemContainerStyle="{StaticResource PointItemStyle}"
ItemContainerStyle="{StaticResource PointItemStyle}" ItemsSource="{Binding Points}"
SelectionMode="Multiple"/> SelectionMode="Multiple"/>
<map:MapItemsControl ItemsSource="{Binding Pushpins}" <map:MapItemsControl ItemContainerStyle="{StaticResource PushpinItemStyle}"
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="65,-18" Content="Iceland"/>
<map:Pushpin AutoCollapse="True" Location="71,25" Content="Norway"/> <map:Pushpin AutoCollapse="True" Location="71,25" Content="Norway"/>