daily pastebin goal
4%
SHARE
TWEET

Untitled

a guest Jan 22nd, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ...
  2. <ListBox.ItemTemplate>
  3.   <DataTemplate>
  4.     <Image Source="{Binding ImageUrl}" Height="90" Width="90" Stretch="UniformToFill" />
  5.   </DataTemplate>
  6. </ListBox.ItemTemplate>
  7. ...
  8.    
  9. public static readonly DependencyProperty DecodingSourceProperty = DependencyProperty.RegisterAttached(
  10. DecodingSourcePropertyName,
  11. typeof (Uri),
  12. typeof (Image),
  13. new PropertyMetadata(null, OnDecodingSourcePropertyChanged));
  14.  
  15. static void OnDecodingSourcePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) {
  16.     var img = d as Image;
  17.     double height = img.Height;
  18.     double width = img.Width;
  19.     var uri = (Uri)e.NewValue;
  20.     var bmp = new WriteableBitmap((int)width, (int)height);
  21.  
  22.     ThreadPool.QueueUserWorkItem(callback => {
  23.         var web = new WebClient();
  24.         web.OpenReadCompleted += (sender, evt) => {
  25.             bmp.LoadJpeg(evt.Result);
  26.             evt.Result.Dispose();
  27.             Deployment.Current.Dispatcher.
  28.             BeginInvoke(() = > {
  29.                 img.Source = bmp;
  30.             });
  31.         };
  32.         web.OpenReadAsync(uri);
  33.     }
  34.     });
  35. }
  36.  
  37. <Image helpers:ImageExt.DecodingSource="{Binding ImageUrl}" Height="90" Width="90" Stretch="UniformToFill" />
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top