C#在Windows Phone 8上的Uri无效。图像Uri System.InvalidOperationException。

时间:2014-09-22 12:49:37

标签: c# image windows-phone-8 windows-phone maps

图片文件位于我的应用的资源文件夹中。我使用完整的uri没有成功。我尝试将其动态添加到我的地图中。其余的代码工作(测试),当我试图从uri获取图像时,我得到这个错误。

Image pin = new Image();
 var uri = new Uri(@"/Assets/shop.png", UriKind.RelativeOrAbsolute);
    pin.Source = new BitmapImage(uri);
 pin.Tag = new GeoCoordinate(coordinate.Latitude, coordinate.Longitude);
        pin.MouseLeftButtonUp += new MouseButtonEventHandler(Marker_Click);
        pin.Height = 20;
        pin.Width = 20;
        pin.Opacity = 50;
        // Create a MapOverlay and add marker.
        MapOverlay overlay = new MapOverlay();
        overlay.Content = pin;
        overlay.GeoCoordinate = new GeoCoordinate(coordinate.Latitude, coordinate.Longitude);
        overlay.PositionOrigin = new Point(0.0, 1.0);
        mapLayer.Add(overlay);

1 个答案:

答案 0 :(得分:0)

试试这个:

Image imgPushpin = new Image();
                        imgPushpin.Height = 60;
                        imgPushpin.Width = 41;
                        imgPushpin.Source = new BitmapImage(new Uri("/Assets/Images/PropertyLocator/imgPropertyPoint.png", UriKind.Relative));
                        imgPushpin.Tag = "Location";
                        imgPushpin.MouseLeftButtonUp += imgPushpinMouseLeftButtonUp;
                        // Create a MapOverlay and add marker
                        MapOverlay overlay = new MapOverlay();
                        overlay.Content = imgPushpin;
                        overlay.GeoCoordinate = new GeoCoordinate(listView[j].latitude, listView[j].longnitude);
                        overlay.PositionOrigin = new Point(0.5, 1);
                        locationLayer = new MapLayer();
                        locationLayer.Add(overlay);
                        mapPropertyLocator.Layers.Add(locationLayer);
                        mapPropertyLocator.ZoomLevel = 11.5;