Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ...
- <ListBox.ItemTemplate>
- <DataTemplate>
- <Image Source="{Binding ImageUrl}" Height="90" Width="90" Stretch="UniformToFill" />
- </DataTemplate>
- </ListBox.ItemTemplate>
- ...
- public static readonly DependencyProperty DecodingSourceProperty = DependencyProperty.RegisterAttached(
- DecodingSourcePropertyName,
- typeof (Uri),
- typeof (Image),
- new PropertyMetadata(null, OnDecodingSourcePropertyChanged));
- static void OnDecodingSourcePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) {
- var img = d as Image;
- double height = img.Height;
- double width = img.Width;
- var uri = (Uri)e.NewValue;
- var bmp = new WriteableBitmap((int)width, (int)height);
- ThreadPool.QueueUserWorkItem(callback => {
- var web = new WebClient();
- web.OpenReadCompleted += (sender, evt) => {
- bmp.LoadJpeg(evt.Result);
- evt.Result.Dispose();
- Deployment.Current.Dispatcher.
- BeginInvoke(() = > {
- img.Source = bmp;
- });
- };
- web.OpenReadAsync(uri);
- }
- });
- }
- <Image helpers:ImageExt.DecodingSource="{Binding ImageUrl}" Height="90" Width="90" Stretch="UniformToFill" />
Add Comment
Please, Sign In to add comment