title: Parameterized Constructor for WinRT UserControl
body: <p>I am trying to create a custom Pushpin for Bing Maps in my WinRT application. My problem is that I need a reference to the actual Map from my page in order to pin the icons correctly in my userControl. So for example this is my DataTemplate which gets bound to the map and works fine for the normal pushpins. For my custom userControl to position correctly I need a reference to the parent Map in the userControl. </p>
  
  <p>This is my XAML:</p>
  
  <pre><code>&lt;m:MapItemsControl x:Name="Pushpinss" ItemsSource="{Binding InventoryItems}"&gt;
          &lt;m:MapItemsControl.ItemTemplate&gt;
            &lt;DataTemplate&gt;
              &lt;!-- NORMAL PUSHPIN WORKS --&gt;
              &lt;m:Pushpin&gt;
                &lt;m:MapLayer.Position&gt;
                  &lt;m:Location Latitude="{Binding WarehouseLatitude}"
                              Longitude="{Binding WarehouseLongitude}" /&gt;
                &lt;/m:MapLayer.Position&gt;
              &lt;/m:Pushpin&gt;
              &lt;!-- CUSTOM CONTROL DISPLAYS BUT DOES NOT POSITION CORRECTLY BECAUSE I NEED A REFERENCE TO THE MAP--&gt;
              &lt;View:GPSIcon  Latitude="{Binding WarehouseLatitude}"
                             Longitude="{Binding WarehouseLongitude}"
                             Radius="100000"/&gt;
                &lt;x:Arguments&gt;
                &lt;/x:Arguments&gt;
            &lt;/DataTemplate&gt;
          &lt;/m:MapItemsControl.ItemTemplate&gt;
        &lt;/m:MapItemsControl&gt;
  </code></pre>
  
  <p>This is my custom control:</p>
  
  <pre><code>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) =&gt;
        {
          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); }
      }
  
      /// &lt;summary&gt;
      /// Radius in Metres
      /// &lt;/summary&gt;
      public double Radius
      {
        get { return (double)GetValue(RadiusProperty); }
        set
        {
          SetValue(RadiusProperty, value);
          UpdateAccuracyCircle();
        }
      }
  
      private void UpdateAccuracyCircle()
      {
        if (_map != null &amp;&amp; Radius &gt;= 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);
        }
      }
    }
  </code></pre>
  
  <p>Is this possible at all? I have also tried using the x:Arguments directive as described here:
  <a href="http://msdn.microsoft.com/en-us/library/ee795382.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/ee795382.aspx</a></p>
  
  <p>Thanks</p>