MVVM Windows Phone 8 – 向地图添加图钉集合
发布时间:2020-12-13 20:35:54 所属栏目:Windows 来源:网络整理
导读:这是XAML代码: maps:Map x:Name="NearbyMap" Center="{Binding MapCenter,Mode=TwoWay}" ZoomLevel="{Binding ZoomLevel,Mode=TwoWay}" maptk:MapExtensions.Children maptk:MapItemsControl Name="StoresMapItemsControl" ItemsSource="{Binding Treks}" m
这是XAML代码:
<maps:Map x:Name="NearbyMap" Center="{Binding MapCenter,Mode=TwoWay}" ZoomLevel="{Binding ZoomLevel,Mode=TwoWay}" > <maptk:MapExtensions.Children> <maptk:MapItemsControl Name="StoresMapItemsControl" ItemsSource="{Binding Treks}"> <maptk:MapItemsControl.ItemTemplate> <DataTemplate> <maptk:Pushpin x:Name="RouteDirectionsPushPin" GeoCoordinate="{Binding Location}" Visibility="Visible" Content="test"/> </DataTemplate> </maptk:MapItemsControl.ItemTemplate> </maptk:MapItemsControl> <maptk:UserLocationMarker x:Name="UserLocationMarker" Visibility="Visible" GeoCoordinate="{Binding MyLocation}"/> </maptk:MapExtensions.Children> </maps:Map> xmlns:maps="clr-namespace:Microsoft.Phone.Maps.Controls;assembly=Microsoft.Phone.Maps" xmlns:maptk="clr-namespace:Microsoft.Phone.Maps.Toolkit;assembly=Microsoft.Phone.Controls.Toolkit" PushPinModel有一个属性Location,它是一个GeoCoordinate. Treks是一个ObservableCollection< PushPinModel>.我运行此代码,只显示UserLocationMarker,这是我当前的位置.
我终于使用依赖属性使其工作.我添加了一个新类:
public static class MapPushPinDependency { public static readonly DependencyProperty ItemsSourceProperty = DependencyProperty.RegisterAttached( "ItemsSource",typeof(IEnumerable),typeof(MapPushPinDependency),new PropertyMetadata(OnPushPinPropertyChanged)); private static void OnPushPinPropertyChanged(DependencyObject d,DependencyPropertyChangedEventArgs e) { UIElement uie = (UIElement)d; var pushpin = MapExtensions.GetChildren((Map)uie).OfType<MapItemsControl>().FirstOrDefault(); pushpin.ItemsSource = (IEnumerable)e.NewValue; } #region Getters and Setters public static IEnumerable GetItemsSource(DependencyObject obj) { return (IEnumerable)obj.GetValue(ItemsSourceProperty); } public static void SetItemsSource(DependencyObject obj,IEnumerable value) { obj.SetValue(ItemsSourceProperty,value); } #endregion } 在我添加的.xaml文件中 xmlns:dp="clr-namespace:Treks.App.Util.DependencyProperties" 现在.xaml文件看起来像这样: <maps:Map x:Name="NearbyMap" Center="{Binding MapCenter,Mode=TwoWay}" dp:MapPushPinDependency.ItemsSource="{Binding Path=Treks}" > <maptk:MapExtensions.Children> <maptk:MapItemsControl Name="StoresMapItemsControl"> <maptk:MapItemsControl.ItemTemplate> <DataTemplate> <maptk:Pushpin x:Name="PushPins" GeoCoordinate="{Binding Location}" Visibility="Visible" Content="test"/> </DataTemplate> </maptk:MapItemsControl.ItemTemplate> </maptk:MapItemsControl> <maptk:UserLocationMarker x:Name="UserLocationMarker" Visibility="Visible" GeoCoordinate="{Binding MyLocation}"/> </maptk:MapExtensions.Children> </maps:Map> 现在所有的图钉都被正确渲染. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- windows系统上安装mysql操作过程及常见错误处理
- windows环境下基于pycharm安装Redis出现的两个错误解决方案
- 第四节:Windows系统安装时BIOS设置及注意
- Windows Phone 8.1 C#app:仅在发布模式下的真实设备上发生
- windows-7 – 如何让非特权用户在Win7中更改/添加路由? Op
- 如何收集每个服务名称及其在Windows中的状态?
- windows – 在命名管道上选择
- 7年Microsoft MVP,是否还能坚持3年
- Hyper-V 2012 R2虚拟机上的INACCESSIBLE_BOOT_DEVICE
- 可以选择()与Windows下的Python文件一起使用吗?
推荐文章
站长推荐
- Windows Azure角色可以检测角色所在的数据中心吗
- windows-xp – 找到瓶颈:Windows XP上的磁盘I /
- windows系统-Android移动端自动化-Appium+Python
- winapi – 在Windows 7上禁用Ctrl Alt Del
- windows-phone-7 – MvvmCross – 为多个视图共享
- windows – 以编程方式在Internet Explorer中设置
- Windows Phone 7 – Windows Phone的单元测试状态
- MariaDB Windows 安装
- 在Windows Powershell中忽略错误级别!= 0
- windows-server-2003 – 服务器实际需要多少RAM?
热点阅读