Vitalii

Untitled

Sep 20th, 2013
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.84 KB | None | 0 0
  1. public class SafePicture : System.Windows.Controls.ContentControl
  2.     {
  3.         private ImageSource imageSource;
  4.  
  5.         public SafePicture()
  6.         {
  7.             Loaded += OnLoaded;
  8.             Unloaded += SafePictureUnloaded;
  9.         }
  10.  
  11.         private void OnLoaded(object _sender, RoutedEventArgs _routedEventArgs)
  12.         {
  13.             var image = Content as System.Windows.Controls.Image;
  14.             if (imageSource != null && image != null)
  15.                     image.Source = imageSource;
  16.         }
  17.  
  18.         private void SafePictureUnloaded(object sender, System.Windows.RoutedEventArgs e)
  19.         {
  20.             var image = Content as System.Windows.Controls.Image;
  21.  
  22.             if (image != null)
  23.             {
  24.                 imageSource = image.Source;
  25.                 image.Source = null;
  26.             }
  27.         }
  28.     }
Advertisement
Add Comment
Please, Sign In to add comment