我正尝试在WinRT应用程序中为Bing地图创建自定义图钉。我的问题是,我需要从我的页面上的实际地图的引用,以便在我的userControl中正确地固定图标。因此,例如,这是我的DataTemplate绑定到地图,并正常工作的图钉。为了让我的自定义userControl正确定位,我需要对userControl中父映射的引用。WinRT UserControl的参数化构造函数
这是我的XAML:
<m:MapItemsControl x:Name="Pushpinss" ItemsSource="{Binding InventoryItems}">
<m:MapItemsControl.ItemTemplate>
<DataTemplate>
<!-- NORMAL PUSHPIN WORKS -->
<m:Pushpin>
<m:MapLayer.Position>
<m:Location Latitude="{Binding WarehouseLatitude}"
Longitude="{Binding WarehouseLongitude}" />
</m:MapLayer.Position>
</m:Pushpin>
<!-- CUSTOM CONTROL DISPLAYS BUT DOES NOT POSITION CORRECTLY BECAUSE I NEED A REFERENCE TO THE MAP-->
<View:GPSIcon Latitude="{Binding WarehouseLatitude}"
Longitude="{Binding WarehouseLongitude}"
Radius="100000"/>
<x:Arguments>
</x:Arguments>
</DataTemplate>
</m:MapItemsControl.ItemTemplate>
</m:MapItemsControl>
这是我的自定义控制:
public sealed partial class GPSIcon : UserControl
{
private Map _map;
private const double EARTH_RADIUS_METERS = 6378137;
public GPSIcon(Map map)
{
this.InitializeComponent();
_map = map;
_map.ViewChanged += (s, e) =>
{
UpdateAccuracyCircle();
};
}
public static readonly DependencyProperty LatitudeProperty =
DependencyProperty.Register("Latitude", typeof(double), typeof(GPSIcon), new PropertyMetadata(0));
public static readonly DependencyProperty LongitudeProperty =
DependencyProperty.Register("Longitude", typeof(double), typeof(GPSIcon), new PropertyMetadata(0));
public static readonly DependencyProperty RadiusProperty =
DependencyProperty.Register("Radius", typeof(double), typeof(GPSIcon), new PropertyMetadata(0));
public double Latitude
{
get { return (double)GetValue(LatitudeProperty); }
set { SetValue(LatitudeProperty, value); }
}
public double Longitude
{
get { return (double)GetValue(LongitudeProperty); }
set { SetValue(LongitudeProperty, value); }
}
/// <summary>
/// Radius in Metres
/// </summary>
public double Radius
{
get { return (double)GetValue(RadiusProperty); }
set
{
SetValue(RadiusProperty, value);
UpdateAccuracyCircle();
}
}
private void UpdateAccuracyCircle()
{
if (_map != null && Radius >= 0)
{
double groundResolution = Math.Cos(_map.Center.Latitude * Math.PI/180) * 2 * Math.PI * EARTH_RADIUS_METERS/(256 * Math.Pow(2, _map.ZoomLevel));
double pixelRadius = Radius/groundResolution;
AccuracyCircle.Width = pixelRadius;
AccuracyCircle.Height = pixelRadius;
AccuracyCircle.Margin = new Thickness(-pixelRadius/2, -pixelRadius/2, 0, 0);
}
}
}
这是可能的呢?我已经使用x也尝试:参数指令如下所述: http://msdn.microsoft.com/en-us/library/ee795382.aspx
感谢
谢谢,我已经试过了,但我不能让它绑定。我应该为WinRT使用什么绑定语法?可视化树是
jqIndy
请参阅更新1. – Xyroid
非常感谢。我不能等待Win8.1发布。调试是一场噩梦。我不得不重新创建这个应用程序,因为我的自定义控件中没有任何工作了,仍然没有出于某种原因。你的例子很有意义。我会让你知道,如果它的工作,当我得到它建立:) – jqIndy