MapControl Template10 - c#

SOLVED
I solved this problem with the fact that I have to add a MapItemsControl.ItemTemplate. Without this it does not render anything more than the name of the control.
So just add this code:
<Maps:MapItemsControl x:Name="mainMapItems" ItemsSource="{Binding MapItems}">
<Maps:MapItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Background="Transparent">
<TextBlock Maps:MapControl.Location="{Binding Location}" Text="{Binding Title}" Maps:MapControl.NormalizedAnchorPoint="0.5,0.5" FontSize="20" Margin="5"/>
</StackPanel>
</DataTemplate>
</Maps:MapItemsControl.ItemTemplate>
</Maps:MapItemsControl>
It's not perfect because this will not give you an icon on the map, but rather just a text. But it can easily be solve with adding Image = "" in the Collection.
I'm trying to use MapControl in a Template10 layout.
The code I use is
MainPage.xaml
<Maps:MapControl x:Name="MapControl1"
ZoomInteractionMode="GestureAndControl"
TiltInteractionMode="GestureAndControl"
MapServiceToken="<ApiCodeHere>"
Loaded="{x:Bind ViewModel.Map_Loaded}"/>
MainPageViewModel.cs
MapControl _Map;
public MapControl Map { get { return _Map; } set { Set(ref _Map, value); RaisePropertyChanged(); } }
public async void Map_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
MapControl newMap = new MapControl();
Geoposition userLocation = await GetUserLocation();
BasicGeoposition GeoPos_UserLocation = new BasicGeoposition() { Latitude = userLocation.Coordinate.Point.Position.Latitude, Longitude = userLocation.Coordinate.Point.Position.Longitude };
BasicGeoposition GeoPos_NorthWest = new BasicGeoposition() { Latitude = userLocation.Coordinate.Point.Position.Latitude + 0.05, Longitude = userLocation.Coordinate.Point.Position.Latitude + 0.1 };
BasicGeoposition GeoPos_SouthEast = new BasicGeoposition() { Latitude = userLocation.Coordinate.Point.Position.Latitude - 0.05, Longitude = userLocation.Coordinate.Point.Position.Latitude - 0.1 };
GeoboundingBox mapBox = new GeoboundingBox(GeoPos_NorthWest, GeoPos_SouthEast);
// Add Point for User
MapIcon Icon_UserLocation = new MapIcon() { Location = new Geopoint(GeoPos_UserLocation) };
newMap.MapElements.Add(Icon_UserLocation);
newMap.Center = new Geopoint(mapBox.Center);
Map = newMap;
await Task.CompletedTask;
}
The Map_Loaded function is fired as exepcted. The thing that I have a trouble with is that if this was a normal project I would set the data directly to MapControl1.Center and MapControl1.MapElements.Add. But since this is a MVVM project this is not how it's done and I'm a bit confused on how to proceed.
I would like to do something like Views.MainPage.MapControl1.Center = new Geopoint(), but that clearly does not work.
Additional Update
As it turns out this was as easy as I thought. It was just a matter of thinking in the right order.
The MapControl has controls for Zooming and Center and such. So for MVVM code this works
Center="{Binding MapCenter,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
Zoom="{Binding MapZoom,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
I have however had issues with setting up MapItems as described in the document I sources to.
To get items on the map you need to add MapItemsControl and it should work like such...
<Maps:MapItemsControl x:Name="mainMapItems" ItemsSource="{Binding MapItems,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"></Maps:MapItemsControl>
But my code in MainPageViewModel.xaml does not work with this. The items does not update.
IList<MapElement> _MapItems;
public IList<MapElement> MapItems { get { return _MapItems; } set { Set(ref _MapItems, value); RaisePropertyChanged(); } }
IList<MapElement> MapItems = new List<MapElement>() {
new MapIcon() {
Location = new Geopoint(GeoPos_UserLocation),
Title = "You Are Here!"
}
};
Sources: Windows 10 SDK Bing Maps Control

Try using
ObservableCollection ObserverableCollection<MapElement> MapItems =
new ObservableCollection<MapElement>();
Since you expecting the item to be "updatable at runtime" or react to changes ObservableCollection behind the scenes implements INPC

I solved this problem with the fact that I have to add a MapItemsControl.ItemTemplate. Without this it does not render anything more than the name of the control.
So just add this code:
<Maps:MapItemsControl x:Name="mainMapItems" ItemsSource="{Binding MapItems}">
<Maps:MapItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Background="Transparent">
<TextBlock Maps:MapControl.Location="{Binding Location}" Text="{Binding Title}" Maps:MapControl.NormalizedAnchorPoint="0.5,0.5" FontSize="20" Margin="5"/>
</StackPanel>
</DataTemplate>
</Maps:MapItemsControl.ItemTemplate>
</Maps:MapItemsControl>
It's not perfect because this will not give you an icon on the map, but rather just a text. But it can easily be solve with adding Image = "" in the Collection.

Related

TextBlock with text highlighting

Faced the need to select a fragment of text in TextBlock, namely certain keywords on which the ListBox was filtered, this text block itself and containing
XAML variant, title property is not bound
<ListBox Name="ProcedureList" ItemsSource="{Binding Path=ProceduresView.View}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Name="ProcedurePanel" PreviewMouseDown="ProcedurePanel_OnPreviewMouseDown">
<DockPanel Width="{c:Binding ElementName=MainPanel, Path=Width-40}">
<!--<TextBlock Name="MainText" TextWrapping="Wrap" FontSize="16" Text="{Binding Path=title}" HorizontalAlignment="Left" />-->
<htb:HighlightTextBlock Name="MainText" TextWrapping="Wrap" FontSize="16" Text="{Binding Path=title}" HorizontalAlignment="Left">
<htb:HighlightTextBlock.HighlightRules>
<htb:HighlightRule
IgnoreCase="{Binding IgnoreCase, Source={StaticResource SourceVm}}"
HightlightedText="{Binding Path=title, Converter={StaticResource getFilter}}">
<htb:HighlightRule.Highlights>
<htb:HighlightBackgroung Brush="Yellow"/>
</htb:HighlightRule.Highlights>
</htb:HighlightRule>
</htb:HighlightTextBlock.HighlightRules>
</htb:HighlightTextBlock>
</DockPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
A component written by our compatriot with open source is used
Component
Description of component
The commented code is an old TexBlock with no selection
The new HighlightTextBlock component perfectly selects the text if you use a static resource, as in the example, but when I try to bind it to the current text it can not find this field :(, I'm new in WPF help figure it out
HightlightedText="{Binding Path=title, Converter={StaticResource getFilter}}"
How correctly to anchor this property to title?
DataContext structure
public ObservableCollection<Procedure> Procedures { set; get; }
public CollectionViewSource ProceduresView { set; get; } = new CollectionViewSource();
....
Procedures = new ObservableCollection<Procedure>();
ProceduresView.Filter += Procedures_Filter;
ProceduresView.Source = Procedures;
....
public class Procedure : ObservableObject
{
....
public String title { get; set; }
....
}
....
// Simple filtering
void Procedures_Filter(object sender, FilterEventArgs e)
{
Procedure procedure = (Procedure) e.Item;
Boolean flag = false;
if (!string.IsNullOrEmpty(filter))
{
Setting.Filter sfilter = new Setting.Filter();
sfilter.type = "искать везде";
sfilter.text = filter;
ObservableCollection<Setting.Filter> arr = new ObservableCollection<Setting.Filter>();
arr.Add(sfilter);
if (Utils.AssignedProcedureFromFilter(procedure, arr)) flag = true;
}
else flag = true;
e.Accepted = flag;
}
Video with problem description
Simplified project emitting my functional
On the Russian-speaking forum they explained to me that:
Your case, in fact, is more serious. DataContext you, apparently, the
right one. But your Binding expression is inside the HighlightRules
property setter, which is not part of the visual tree (because it is
not available as a Child element of your control). And elements that
are not inside the visual tree, participate in bindings are only
limited: they do not inherit DataContext, nor access by name through
ElementName. As a solution, bind to an element via x: Reference. In my
(heavily cut) test case, HightlightedText = "{Binding Path =
DataContext.title, Source = {x: Reference MainText}} is triggered."
But, if directly replaced by this, a strange error works: 'Can not
call MarkupExtension. ProvideValue because of a cyclic dependency. The
properties inside the MarkupExtension can not reference objects that
reference the MarkupExtension result.
The workaround for the error was found here: you need to put your element in resources. We get this:
XAML, modified according to the recommendations
<ListBox Name="ProcedureList" ItemsSource="{Binding Path=ProceduresView.View}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Name="ProcedurePanel" PreviewMouseDown="ProcedurePanel_OnPreviewMouseDown">
<DockPanel Width="{c:Binding ElementName=MainPanel, Path=Width-40}">
<!--<TextBlock Name="MainText" TextWrapping="Wrap" FontSize="16" Text="{Binding Path=title}" HorizontalAlignment="Left" />-->
<htb:HighlightTextBlock Name="MainText" TextWrapping="Wrap" FontSize="16"
Text="{Binding Path=title}" HorizontalAlignment="Left">
<htb:HighlightTextBlock.Resources>
<htb:HighlightRule x:Key="HR"
IgnoreCase="{Binding IgnoreCase, Source={StaticResource SourceVm}}"
HightlightedText="{Binding Path=DataContext.title, Source={x:Reference MainText}, Converter={StaticResource getFilter}}">
<htb:HighlightRule.Highlights>
<htb:HighlightBackgroung Brush="Yellow"/>
</htb:HighlightRule.Highlights>
</htb:HighlightRule>
</htb:HighlightTextBlock.Resources>
<htb:HighlightTextBlock.HighlightRules>
<htb:HighlightRulesCollection>
<StaticResource ResourceKey="HR"/>
</htb:HighlightRulesCollection>
</htb:HighlightTextBlock.HighlightRules>
</htb:HighlightTextBlock>
</DockPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
I was given advice on the restructuring of XAML, through resources, this partially solved the problem (I successfully got the title text in the converter), but the element ceased to perform its functions (allocation) During the discussion, it was suggested that the component itself should be finalized
#iRumba: In theory, the whole trick should not be necessary if you put
the HighlighRule collection (also) in a visual tree. Then the
DataContext will be automatically inherited and on idea the binding
through ElementName too will work.
#iRumba: I do not remember exactly. It seems, it is necessary to
specify to add all HighlightRule as LogicalChildren (for this purpose
on idea it is necessary to redefine protected internal override
IEnumerator LogicalChildren). This is a complicated, advanced
technique, yes.
Sorry for Google Translator
Found a solution
public class SearchHightlightTextBlock : TextBlock
{
public SearchHightlightTextBlock() : base() { }
public String SearchText
{
get { return (String)GetValue(SearchTextProperty); }
set { SetValue(SearchTextProperty, value); }
}
private static void OnDataChanged(DependencyObject source,
DependencyPropertyChangedEventArgs e)
{
TextBlock tb = (TextBlock)source;
if (tb.Text.Length == 0)
return;
string textUpper = tb.Text.ToUpper();
String toFind = ((String)e.NewValue).ToUpper();
int firstIndex = textUpper.IndexOf(toFind);
String firstStr = "";
String foundStr = "";
if (firstIndex != -1)
{
firstStr = tb.Text.Substring(0, firstIndex);
foundStr = tb.Text.Substring(firstIndex, toFind.Length);
}
String endStr = tb.Text.Substring(firstIndex + toFind.Length,
tb.Text.Length - (firstIndex + toFind.Length));
tb.Inlines.Clear();
tb.FontSize = 16;
var run = new Run();
run.Text = firstStr;
tb.Inlines.Add(run);
run = new Run();
run.Background = Brushes.Yellow;
run.Text = foundStr;
tb.Inlines.Add(run);
run = new Run();
run.Text = endStr;
tb.Inlines.Add(run);
}
public static readonly DependencyProperty SearchTextProperty =
DependencyProperty.Register("SearchText",
typeof(String),
typeof(SearchHightlightTextBlock),
new FrameworkPropertyMetadata(null, OnDataChanged));
}
Use
<parser:SearchHightlightTextBlock SearchText="{Binding Path=title, Converter={StaticResource getFilter}}" Text="{Binding title}"/>

Windows Phone 8.1 with Bing maps returns Access violation

I am trying to bind a collections of points to the Bing map control and everything works great for the first time (when I am opening the view with this map for the first time) but every another attempt end up with this pure message in the output window:
The program 'xxx' has exited with code -1073741819 (0xc0000005) 'Access violation'.
There is no exceptions, nothing only this message. What I have tried so far is this article from MSDN but without success. I have also tried to run the code on the UI thread but it didn't help.
In the ViewModel I am doing this:
Issues.Completed += () =>
{
Locations = new ObservableCollection<MapItemViewModel>();
foreach (var issueLto in Issues.Result)
{
Locations.Add(new MapItemViewModel
{
Name = issueLto.Title,
Location = new MapPointViewModel
{
Longitude = issueLto.Longitude,
Latitude = issueLto.Latitude
}
});
}
MapCenter = Issues.Result.Select(c => new MapCenterViewModel
{
Location = new MapPointViewModel
{
Latitude = c.Latitude,
Longitude = c.Longitude
}
}).FirstOrDefault();
};
And the XAML:
<maps:MapControl
MapServiceToken="{StaticResource BingServiceToken}"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
Center="{Binding MapCenter.Location, Converter={StaticResource MapCoordinatesConverter}}">
<maps:MapItemsControl ItemsSource="{Binding Locations}">
<maps:MapItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel maps:MapControl.Location="{Binding Location, Converter={StaticResource MapCoordinatesConverter}}">
<TextBlock Text="{Binding Name}" Foreground="Black"/>
<Image Source="../../Assets/mappin.png" Height="25"/>
</StackPanel>
</DataTemplate>
</maps:MapItemsControl.ItemTemplate>
</maps:MapItemsControl>
</maps:MapControl>
It's maybe because you can't bind the center property of the Map Control, there's a workaround using Behavior SDK, please read this article:
http://dreamteam-mobile.com/blog/2012/10/better-bing-maps-sdk-for-metro-apps-winrt-windows8-en/
in MSDN, this is helpful:
https://social.msdn.microsoft.com/Forums/en-US/436fc737-19c8-4832-a1c4-368f88063616/anyway-to-make-a-binding?forum=bingmapswindows8

How to add a UI element above Map Icon to show address in Windows 10?

I am working on MapControl in Windows 10 and I want to display Location Address above map icon. I know how to add a map icon but not aware of adding a UI element above it. I added Map Icon using following code
MapControl map = frameworkElement as MapControl;
map.MapServiceToken= "my service token";
BasicGeoposition councilPosition = new BasicGeoposition()
{
Latitude = Convert.ToDouble(Info.GetType().GetRuntimeProperty("LATITUDE").GetValue(Info, null)),
Longitude = Convert.ToDouble(Info.GetType().GetRuntimeProperty("LONGITUDE").GetValue(Info, null))
};
Geopoint pinPoint = new Geopoint(councilPosition);
MapIcon locationPin = new MapIcon();
locationPin.Image= RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Images/pushpin.png"));
locationPin.Title = councilInfo.COUNCIL_NAME;
locationPin.CollisionBehaviorDesired = MapElementCollisionBehavior.RemainVisible;
locationPin.Location = councilPoint;
locationPin.NormalizedAnchorPoint = new Point(0.5, 1.0);
locationPin.ZIndex = 0;
map.MapElements.Add(locationPin);
await map.TrySetViewAsync(locationPin.Location, 15D, 0, 0, MapAnimationKind.Bow);
and I want to achieve same as below screenshots
Since programmatic adding MapIcons is hectic for custom template. Here's how I am using map Control inside my app
<maps:MapControl x:Name="MapControl" MapServiceToken="YourToken" >
<maps:MapItemsControl ItemsSource="{Binding YourData, Mode=TwoWay}">
<maps:MapItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Tapped="MapIcon_Tapped" Orientation="Horizontal">
<Image Height="30" VerticalAlignment="Top" maps:MapControl.Location="{Binding Location}" maps:MapControl.NormalizedAnchorPoint="0.5,0.5" Source="ms-appx:///Images/pushpin.png"/>
<Border BorderThickness="1" BorderBrush="LightGray" Visibility="{Binding DetailsVisibility}">
<StackPanel x:Name="MapIcon" Background="White" >
<TextBlock Text="{Binding yourMin}" Foreground="Black" FontWeight="SemiBold" FontSize="16" Margin="5" TextWrapping="WrapWholeWords" />
<TextBlock Text="{Binding YourCar}" Foreground="Gray" FontWeight="SemiBold" FontSize="12" Margin="5" TextWrapping="WrapWholeWords"/>
<Image Source="Your Arrow"/>
</StackPanel>
</Border>
</StackPanel>
</DataTemplate>
</maps:MapItemsControl.ItemTemplate>
</maps:MapItemsControl>
</maps:MapControl>
Now here you just need to keep adding data to YourData to add more pushpin.
There are two properties added
1. Location- Is of Geopoint type which will take care of position where pushpin should be placed based on latitude and longitude e.g temp.Location = new Geopoint(new BasicGeoposition { Latitude = double.Parse(temp.Lat), Longitude = double.Parse(temp.Long) });
2. Visibility- This will be used to handle the pushpin detail visibility to be available only on taping it. eg. temp.DetailsVisibility = Windows.UI.Xaml.Visibility.Collapsed;
You will need to add these values to YourData for binding.
I know how to add a map icon but not aware of adding a UI element above it.
If you need to add UIElement above the MapIcon, a possible way is to add UIElement into MapControl’s Children and set to the same coordinate( MapControl.SetLocation).
Here is a simple sample:
BasicGeoposition snPosition = new BasicGeoposition() { Latitude = 47.643, Longitude = -122.131 };
Geopoint snPoint = new Geopoint(snPosition);
Grid MyGrid = new Grid();
MyGrid.Background = new SolidColorBrush(Windows.UI.Colors.Blue);
TextBlock text = new TextBlock();
text.Text = "Hello";
text.Width = 200;
MyGrid.Children.Add(text);
MyMapControl.Center = snPoint;
MyMapControl.ZoomLevel = 14;
// Get the address from a `Geopoint` location.
MapLocationFinderResult result = await MapLocationFinder.FindLocationsAtAsync(snPoint);
if (result.Status == MapLocationFinderStatus.Success)
{
text.Text = "Street = " + result.Locations[0].Address.Street;
}
MyMapControl.Children.Add(MyGrid);
MapControl.SetLocation(MyGrid, snPoint);
MapControl.SetNormalizedAnchorPoint(MyGrid, new Point(0.5, 0.5));
Screenshot(gif):

Multimarkers in a bing Map

I am having a problem in putting a marker for every location in my bing map, this is my code:
private async void geolocator_PositionChanged(Geolocator sender, PositionChangedEventArgs args)
{
await
// Need to get back onto UI thread before updating location information
this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, new DispatchedHandler(
async () =>
{
UriString4 = "my URL";
var http = new HttpClient();
http.MaxResponseContentBufferSize = Int32.MaxValue;
var response = await http.GetStringAsync(UriString4);
var rootObject = JsonConvert.DeserializeObject<NvBarberry.Models.RootObject>(response);
Location[] location = new Location[int.Parse(rootObject.total)];
for (int i = 0; i < int.Parse(rootObject.total); i++)
{
//Get the current location
location[i] = new Location(rootObject.locals[i].local_latit,rootObject.locals[i].local_longi);
//Update the position of the GPS pushpin
MapLayer.SetPosition(GpsIcon, location[i]);
//Set the radius of the Accuracy Circle
GpsIcon.SetRadius(args.Position.Coordinate.Accuracy);
//Make GPS pushpin visible
GpsIcon.Visibility = Windows.UI.Xaml.Visibility.Visible;
//Update the map view to the current GPS location
MyMap.SetView(location[i], 17);
}
}));}
This is the JSON data from where I want to get the local_longi and
local_latit of every Location:
{
success : 1,
total : 2,
locals : [{
id_local : "59",
local_longi : "20",
local_latit : "25894"
}, {
id_local : "60",
local_longi : "10.33699",
local_latit : "25.997745"
}
]
}
The problem is that I get only one marker on the map, which is the last Location from Longitude, Lattitude (according to tha JSON data I get on Map only the location with this values:
local_longi: "10.33699",
local_latit: "25.997745"
And this is what I get when debugging:
I get all results in "location" variable, why I get only one marker in the Map
this is the tutorial that I have followed:
https://blogs.bing.com/maps/2012/11/05/getting-started-with-bing-maps-windows-store-apps-native/
Update:
this is my xaml code for the Map:
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<m:Map Name="MyMap" Credentials="1m8dxWklva2lte3kYjkn~........" ZoomLevel="13" />
<CheckBox Content="GPS" Click="GPS_Checked"/>
</Grid>
Hey try to bind a OberservableCollection of Pushpin(Class from me).
<Maps:MapItemsControl ItemsSource="{x:Bind ViewModel.Pushpins}">
<Maps:MapItemsControl.ItemTemplate>
<DataTemplate x:DataType="model:Pushpin">
<StackPanel Maps:MapControl.Location="{x:Bind Location, Converter={StaticResource PointConverter}}"
Maps:MapControl.NormalizedAnchorPoint="{x:Bind Path='', Converter={StaticResource DefaultAnchorPointConverter}}">
<TextBlock Text="{x:Bind Title}"
Foreground="Black" />
<Image Source="{x:Bind Path='', Converter={StaticResource PushpinConverter}}" />
</StackPanel>
</DataTemplate>
</Maps:MapItemsControl.ItemTemplate>
</Maps:MapItemsControl>

showing multiple pushpins on a map in windows phone using mvvm model

I have the following view in my mvvm model based app which should display all the pushpins I bind to it using binding property "PushPinLocation" from my view model.
<MapNS:Map
Center="{Binding MapCenter, Mode=TwoWay}" Margin="0,0,-5,0"
CartographicMode="{Binding MapMode, Mode=TwoWay}"
LandmarksEnabled="True" PedestrianFeaturesEnabled="True"
ZoomLevel="{Binding MapZoomLevel, Mode=TwoWay}"
Foreground="AliceBlue" Grid.Row="1" Height="713" Width="425"
x:Name="mapPanoramaAddress" >
<!--Adding Location to show map initially until the data arrived-->
<maptk:MapExtensions.Children>
<maptk:MapItemsControl Name="StoresMapItemsControl" >
<maptk:MapItemsControl.ItemTemplate>
<DataTemplate>
<maptk:Pushpin x:Name="PushPins" Background="White"
GeoCoordinate="{Binding PushPinLocation}"
Content="{Binding PushPinDisplayText}"
Visibility="Visible" />
</DataTemplate>
</maptk:MapItemsControl.ItemTemplate>
</maptk:MapItemsControl>
<maptk:UserLocationMarker GeoCoordinate="{Binding PushPinLocation}" x:Name="UserLocationMarker" Visibility="Visible" />
</maptk:MapExtensions.Children>
</MapNS:Map>
In the geolocator positionchanged event which triggers for every few meters I am setting the value for binding property "PushPinLocation" (from my view model) which is common for pushpin and location marker.
//PushPinLocation
private GeoCoordinate _PushPinLocation = new GeoCoordinate(40.712923, -74.013292); //cannot assign null
public GeoCoordinate PushPinLocation
{
get { return _PushPinLocation; }
set
{
if (_PushPinLocation != value)
{
_PushPinLocation = value;
RaisePropertyChanged("PushPinLocation");
}
}
}
in the same viewmodel geolocator_Position changed event I am setting the pushpinlocation:
private void geolocator_PositionChanged(Geolocator sender, PositionChangedEventArgs args)
{
this.PushPinLocation = args.Position.Coordinate.ToGeoCoordinate();
}
But I always see the latest one showing up and old ones are never shown on the map.Is there any way I can retain the old ones as well.
This post is a year old, but unanswered, so here is my answer:
Instead of binding to a single PushPinLocation, use a collection. In your ViewModel, add this:
private List<GeoCoordinate> _pushPinLocations;
public List<GeoCoordinate> PushPinLocations
{
get { return _pushPinLocations; }
set
{
_pushPinLocations = value;
OnPropertyChanged("PushPinLocations");
}
}
and change your event to:
private void geolocator_PositionChanged(Geolocator sender, PositionChangedEventArgs args)
{
this.PushPinLocations.Add(args.Position.Coordinate.ToGeoCoordinate());
}
That will add the new location to the list and as long as its bound to this list of locations, all pins will show.
<maptk:MapItemsControl Name="StoresMapItemsControl" >
<maptk:MapItemsControl.ItemTemplate>
<DataTemplate>
<maptk:Pushpin x:Name="PushPins" Background="White"
GeoCoordinate="{Binding PushPinLocations}"
Content="{Binding PushPinDisplayText}"
Visibility="Visible" />
</DataTemplate>
</maptk:MapItemsControl.ItemTemplate>
</maptk:MapItemsControl>

Categories