Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7593923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:17:34+00:00 2026-05-30T21:17:34+00:00

I am trying to visually show that an item (a BitmapImage in my case)

  • 0

I am trying to visually show that an item (a BitmapImage in my case) has been added to a collection in a ListBox using WPF/MVVM. To give some background, I’m capturing streaming video with a capture card, and I’m taking still images while the video is streaming. These images are captured by clicking the “Still Image” button on the UI. After capturing an image, I would like for a thumbnail of said image in a separate panel on the UI. I understand what needs to be done to do this, but I can’t seem to get it to work. Right now, my Model does all the data retrieval.

public ObservableCollection<BitmapImage> GetAssetThumbnails()
{
    var imageDir = ImgPath != null ? new DirectoryInfo(ImgPath) : null;
    if(imageDir != null)
    {
        try
        {
            foreach (FileInfo imageFile in imageDir.GetFiles("*.jpg"))
            {
                var uri = new Uri(imageFile.FullName);
                _assetThumbnails.Add(new BitmapImage(uri));
            }

        }
        catch (Exception)
        {
            return null;
        }
    }

    return _assetThumbnails;
}

My ViewModel creates a new instance of the model in its constructor, and then sets the public property AssetCollection equal to _assetModel.GetAssetThumbnails(). The ViewModel has all the standard OnPropertyChanged events and event handling.

private void OnPropertyChanged(string propertyName)
{
    if(PropertyChanged != null)
    {
        PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
    }
}

#region Public Properties
public ObservableCollection<BitmapImage> AssetCollection
{
    get { return _assetCollection; }
    set
    {
        if (_assetCollection != value)
        {
            _assetCollection = value;
            OnPropertyChanged("AssetCollection");    
        }
    }
}
#endregion

private void _assetCollection_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
    OnPropertyChanged("AssetCollection");
}
public event PropertyChangedEventHandler PropertyChanged;

Then, in my XAML file, I bind the ListBox’s item source to AssetCollection.

<ListBox x:Name="lstBoxAssets" ItemsSource="{Binding AssetCollection}" Grid.Row="1" Background="{DynamicResource GrayColor}" Margin="5,0,0,5" ></ListBox>   

I’ve read that each item in the collection should implement the INotifyPropertyChanged interface. I tried creating a wrapper class for a bitmap image that implemented that, but it didn’t work either. Is there something that I’m missing here? The images show up initially, but don’t refresh after an image has been captured and saved. I have a feeling it’s stemming from the event PropertyChanged not getting called. I noticed through debugging that it is always null when it’s checked, and thus the OnPropetyChanged method is never called. I’m not sure where I should add this event handler though. I only use the code-behind file to add the data context of the view model to the view, and that’s it. That is where I would normally think to add any event handling. Can anyone see something simple that I am missing here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T21:17:35+00:00Added an answer on May 30, 2026 at 9:17 pm

    Are you changing the ObservableCollection when you update the list, or are you changing the items stored inside the collection?

    If you’re changing the items inside the collection, you need to find a way to tell WPF that the collection has changed when the individual items change so it knows to redraw it.

    Usually the items in the collection implement INotifyPropertyChanged, so it’s easy to attach a PropertyChange notification to the items in the list which tells WPF to raise the CollectionChanged event whenever a property changes.

    // Wireup CollectionChanged in Constructor
    public MyViewModel()
    {
        ListOfSomeItems = new List<SomeItem>();
        AssetCollection.CollectionChanged += AssetCollection_CollectionChanged;
    }
    
    // In CollectionChanged event, wire up PropertyChanged event on items
    void AssetCollection_CollectionChanged(object sender, CollectionChangedEventArgs e)
    {
        if (e.NewItems != null)
        {
            foreach(Asset item in e.NewItems)
                item.PropertyChanged += Asset_PropertyChanged;
        }
        if (e.OldItems != null)
        {
            foreach(Asset item in e.OldItems)
                item.PropertyChanged -= Asset_PropertyChanged;
        }
    }
    
    // In PropertyChanged, raise CollectionChanged event
    void Asset_PropertyChanged(object sender, PropertyChangedEventArgs e)
    {
        OnPropertyChanged("AssetCollection");
    }
    

    If the items don’t implement INotifyPropertyChanged, you’ll have to manually raise the CollectionChanged event anytime an item in the collection changes.

    AssetCollection[0].Thumbnail = new BitmapImage(uri);
    OnPropertyChanged("AssetCollection");
    

    If you are changing the ObservableCollection itself by adding/removing items and are not seeing the UI update, then it sounds like it might be a syntax error somewhere we can’t see.

    The most common one I see is making changes to the private property and not the public property.

    // Will not raise the CollectionChanged notification
    _assetCollection = _assetModel.GetAssetThumbnails();
    
    // Will raise the CollectionChanged notification
    AssetCollection = _assetModel.GetAssetThumbnails();
    

    Although I also see a lot of people who use a List or custom collection instead of an ObservableCollection as well, which does not raise the CollectionChanged event.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to build this very simple (visually speaking) layout using HTML/CSS that
I have a function that tracks the user's mouse to show them visually where
I'm trying to create a canvas script that visually draws a cubic bezier-curve, but
I've been battling trying to figure out how to visually create a table. It's
Trying to find some simple SQL Server PIVOT examples. Most of the examples that
Trying to make a make generic select control that I can dynamically add elements
Trying to do this sort of thing... WHERE username LIKE '%$str%' ...but using bound
Trying to perform a single boolean NOT operation, it appears that under MS SQL
Trying to honor a feature request from our customers, I'd like that my application,
Here's what I am trying to do: Build a custom control that essentially is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.