private static void bitmapBorderThicknessChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e) { bitmapBorderThickness = int.Parse(e.NewValue.ToString()); SmartImage input = (SmartImage)d; SetImage(input); }
private static void uriSourceChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e) { uriSource = e.NewValue as string; SmartImage input = (SmartImage)d; SetImage(input); }
private static void SetImage(SmartImage input) { if (string.IsNullOrEmpty(uriSource)) { return; } if (bitmapHeight < 0) { return; } if (bitmapBorderThickness < 0) { return; } try { // do this so that we can handle the completion of an image download // via the event System.Threading.Thread thread = new System.Threading.Thread( new System.Threading.ThreadStart( delegate() { input.imgSmart.Dispatcher.Invoke( System.Windows.Threading.DispatcherPriority.Normal, new Action( delegate() { string packUriBlank = string.Format("pack://application:,,,/{0};component/Images/blankposter.png", Constants.AssemblyName); BitmapImage bmp = new BitmapImage(); bmp.BeginInit(); if (File.Exists(uriSource)) { bmp.UriSource = new Uri(uriSource); } else { bmp.UriSource = new Uri(packUriBlank); } bmp.DecodePixelHeight = bitmapHeight; bmp.EndInit(); input.imgSmart.Height = bitmapHeight; input.bdrSmart.Padding = new Thickness(bitmapBorderThickness); input.imgSmart.Source = bmp; } )); } )); thread.Start(); } catch (Exception ex) { logger.ErrorException(ex.ToString(), ex); } }
private static void SetImage(SmartImage input) { if (string.IsNullOrEmpty(uriSource)) return; if (bitmapHeight < 0) return; if (bitmapBorderThickness < 0) return; try { // do this so that we can handle the completion of an image download // via the event System.Threading.Thread thread = new System.Threading.Thread( new System.Threading.ThreadStart( delegate () { input.imgSmart.Dispatcher.Invoke( System.Windows.Threading.DispatcherPriority.Normal, new Action( delegate () { string packUriBlank = string.Format("pack://application:,,,/{0};component/Images/blankposter.png", Constants.AssemblyName); BitmapImage bmp = new BitmapImage(); bmp.BeginInit(); if (File.Exists(uriSource)) bmp.UriSource = new Uri(uriSource); else bmp.UriSource = new Uri(packUriBlank); bmp.DecodePixelHeight = bitmapHeight; bmp.EndInit(); input.imgSmart.Height = bitmapHeight; input.bdrSmart.Padding = new Thickness(bitmapBorderThickness); input.imgSmart.Source = bmp; } )); } )); thread.Start(); } catch (Exception ex) { logger.ErrorException(ex.ToString(), ex); } }