---
title: "Should I use an ObservableCollection for Images in wpf?"  
description: "Should I use an ObservableCollection for Images in wpf?"  
author: "Anonymous User"  
published: 2013-08-10  
updated: 2013-08-10  
canonical: https://www.mindstick.com/forum/1368/should-i-use-an-observablecollection-for-images-in-wpf  
category: "wpf"  
tags: ["wpf"]  
reading_time: 2 minutes  

---

# Should I use an ObservableCollection for Images in wpf?

\

I am using a [mvvm pattern](https://www.mindstick.com/forum/157860/how-does-the-mvvm-pattern-work-in-knockoutjs-and-why-is-it-important) for an [application](https://www.mindstick.com/articles/12824/calculator-application-in-android) that sources its data from a sql ce [database](https://www.mindstick.com/articles/12226/use-of-database-in-sencha-extjs-and-insert-record-from-user-form-using-ajax) using the [Entity Framework](https://www.mindstick.com/articles/1566/crud-operations-using-entity-framework-code-first-approach) version 4. The WPF application only has one view (don't need [anymore as](https://answers.mindstick.com/qa/37462/why-don-t-we-get-as-much-snow-anymore-as-we-used-to) the app is not that big). I am displaying a [collection](https://www.mindstick.com/articles/1718/collections-in-java) of [properties](https://www.mindstick.com/articles/23331/nootropics-7-different-types-and-their-unique-properties) from the database in a listbox, by creating an [observablecollection](https://www.mindstick.com/forum/1367/difference-between-observablecollection-and-bindinglist-in-wpf) in my [viewmodel](https://www.mindstick.com/forum/157215/what-is-viewmodel-in-mvc) and binding this. This works exactly as expected. The issue is that I now have another listbox (in the same view) that needs to be populated with Images for each property. To be clear, each property has a bunch of images, but each image is only assigned to one property.

What would be the best way to display the images, I thought maybe creating another observablecollection for the images, but I am not sure how I would then ensure that only images for the appropriate property are shown. Or should I simply bind the listbox to the Images property of each property (house)?

private void Load()

{

PropertyList = new ObservableCollection<Property>((from property in entities.Properties.Include("Images")

select property));

propertyView = CollectionViewSource.GetDefaultView(PropertyList);

if (propertyView != null)

propertyView.CurrentChanged += new System.EventHandler(propertyView_CurrentChanged);

RaisePropertyChanged("CurrentContact");

RaisePropertyChanged("SaleTitle");

RaisePropertyChanged("Address");

RaisePropertyChanged("AuctioneerName");

RaisePropertyChanged("AgentName");

RaisePropertyChanged("Price");

RaisePropertyChanged("NextBid");

RaisePropertyChanged("Status");

}

## Replies

### Reply by Pravesh Singh

That sounds distinctly like a different responsibility (a master/details view). In the true spirit of MVVM I'd create a new View and a new ViewModel - perhaps:

```
PropertyImagesViewModel    - public Property
Property { get; set; }    - public
IList<Image> Images { get; set; }    - public int
SelectedIndex { get; set; }
```

## PropertyImagesView

Don't forgot to call RaisePropertyChanged() in each of the property setters

Also note that ObservableCollection does nothing if you aren't manipulating the contents one-at-a-time. If all do you is update the entire collection all-at-once, then it gives you no tangible benefit.

Another thing - if you need to notify that all your properties changed:

RaisePropertyChanged(null);

will do the trick.


---

Original Source: https://www.mindstick.com/forum/1368/should-i-use-an-observablecollection-for-images-in-wpf

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
