title: Image Loading problem in Listbox, WP7
body: <p>I have a Listbox in which every element has an image that is already stored as content.
  I choose the image to be displayed using a converter.</p>
  
  <p>If the image for the corresponding value does not exist, I have to display a default image
  which I have handled in the ImageFailed event.</p>
  
  <p>The problem is that when I run the program I am getting the default image for a few images that already exist.
  If I scroll down the list box and back up again sometimes an image which was displayed properly displays the default image.
  This seems to be an performance issue. </p>
  
  <p>I am new to application development, Let me know any detail even though it might seem trivial to you.</p>
  
  <p>Below is my implementation</p>
  
  <pre><code>&lt;ListBox DataContext="{Binding}"&gt;
      &lt;ListBox.ItemTemplate&gt;
          &lt;DataTemplate&gt;
                  &lt;StackPanel&gt;
                              &lt;Image Width="90" Height="67" Source="{Binding id,Converter={StaticResource imageConverter}}" ImageFailed="ImageFailed" /&gt;
                               _
                               _
                      &lt;/StackPanel&gt;
          &lt;/DataTemplate&gt;
      &lt;/ListBox.ItemTemplate&gt;
  &lt;/ListBox&gt;
  </code></pre>
  
  <p>The convert function</p>
  
  <pre><code>public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  {
         string Id = (string)value;
     string imagePath;
     imagePath = string.Format(AppDefines.channelLogoImgPath, prgSvcId);
     return imagePath;
  }
  </code></pre>
  
  <p>The ImageFailed handler</p>
  
  <pre><code>private void ImageFailed(object sender, ExceptionRoutedEventArgs e)
  {
      Image Img = (Image)sender;
      string imgPath = Defines.defImagePath
      Uri uri = new Uri(imgPath, UriKind.RelativeOrAbsolute);
      BitmapImage bDefImage = new BitmapImage(uri);
      Img.Source = bDefImage;
  }
  </code></pre>