WP7中判断图片是否存在

    string mapPath = station.mapPath;
            Uri imageUri = new Uri("/Subway;component/" + mapPath, UriKind.Relative); // mapPath对应图片BuildAction为Resource;  Subway指的是工程名

    // Uri imageUri = new Uri(mapPath, UriKind.Relative); // mapPath对应图片BuildAction为Content
            System.Windows.Resources.StreamResourceInfo sri = Application.GetResourceStream(imageUri);
            if (sri == null)
            {
                // 图片不存在

                BrieflyImage.Source = new BitmapImage(new Uri(StaticStrings.DefaultStationPicturePath, UriKind.RelativeOrAbsolute));
            }
            else
            {

       // 图片存在
                BitmapImage image = new BitmapImage();
                image.SetSource(sri.Stream);
                BrieflyImage.Source = image;
            }

你可能感兴趣的:(wp7)