public object Convert(object value, Type targetType, object parameter, string language) { string uriString = (value == null) ? string.Empty : (string)value; string converterParam = (string)parameter; BitmapImage image = new BitmapImage(); image.DecodePixelType = DecodePixelType.Logical; if (converterParam != null) { if (converterParam.StartsWith("w")) { image.DecodePixelWidth = Int32.Parse(converterParam.Remove(0, 1)); } else if (converterParam.StartsWith("h")) { image.DecodePixelHeight = Int32.Parse(converterParam.Remove(0, 1)); } } string proxyScheme = "image://"; if (uriString.StartsWith(proxyScheme)) { image.SetProxySourceAsync(uriString); } else { Uri defaultUri = new Uri("ms-appx:///Assets/DefaultArt.jpg", UriKind.Absolute); image.UriSource = defaultUri; } return image; }
public object Convert(object value, Type targetType, object parameter, string language) { string imagePath = (value == null) ? string.Empty : (string)value; BitmapImage image = new BitmapImage(); string proxyScheme = "image://"; if (imagePath.StartsWith(proxyScheme)) { image.SetProxySourceAsync(imagePath); } ImageBrush imageBrush = new ImageBrush(); imageBrush.Stretch = Stretch.UniformToFill; imageBrush.Opacity = 0.6; imageBrush.ImageSource = image; return imageBrush; }