forum

Home / DeveloperSection / Forums / Should I use an ObservableCollection for Images in wpf?

Should I use an ObservableCollection for Images in wpf?

Anonymous User285810-Aug-2013


I am using a mvvm pattern for an application that sources its data from a sql ce database using the Entity Framework version 4. The WPF application only has one view (don't need anymore as the app is not that big). I am displaying a collection of properties from the database in a listbox, by creating an observablecollection in my viewmodel 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");

    }


Updated on 10-Aug-2013
I am a content writter !

Can you answer this question?


Answer

1 Answers

Liked By