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 8345499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:41:32+00:00 2026-06-09T06:41:32+00:00

I’m trying to use databinding in WPF with an MVVM pattern. So far, it

  • 0

I’m trying to use databinding in WPF with an MVVM pattern. So far, it seems that everything is plumbed up properly and I’m using the right type of classes and objects. My observable collection loads to first time correctly, but won’t refresh on the datagrid when it changes. Observable Collections should automatically implement INPC and I’ve also provided a handler for it in my base class, so I’m confused why it is still not working and updating my UI. Here’s my code below:

ViewModelBase Class:

#Region "INotifyPropertyChanged Members"
Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
Protected Overridable Sub OnPropertyChanged(ByVal propertyName As String)
    VerifyPropertyName(propertyName)
    Dim handler As PropertyChangedEventHandler = PropertyChangedEvent
    If handler IsNot Nothing Then
        Dim e = New PropertyChangedEventArgs(propertyName)
        handler(Me, e)
    End If
End Sub
#End Region

MainWindowViewModel Class:

Public Class MainWindowViewModel
    Inherits ViewModelBase

    Private Shared _coreInfoData As ObservableCollection(Of Person)
    Public Shared Property CoreInfoData() As ObservableCollection(Of Person)
        Get
            Return _coreInfoData
        End Get
        Set(ByVal value As ObservableCollection(Of Person))
            _coreInfoData = value
        End Set

    Public Sub Main()
        If CoreInfoData IsNot Nothing Then
            CoreInfoData.Clear()
        End If
        CoreInfoData = GetRecords()
    End Sub

The GetRecords function is a call to a database that gets the most recent set of records available.

In my view, I’m actually binding to a CollectionViewSource and binding that to a datagrid:

<UserControl.Resources>
    <CollectionViewSource Source="{Binding Path=CoreInfoData, Mode=TwoWay}" x:Key="cvs">
        <CollectionViewSource.GroupDescriptions>
            <dat:PropertyGroupDescription PropertyName="GroupId"/>
        </CollectionViewSource.GroupDescriptions>
    </CollectionViewSource>
</UserControl.Resources>
<DataGrid ItemsSource="{Binding Source={StaticResource cvs}}" AutoGenerateColumns="False" >
    <DataGrid.Columns>
        <DataGridTextColumn Header="Last Name" Binding="{Binding Path=LastName}" IsReadOnly="True" />
        <DataGridTextColumn Header="First Name" Binding="{Binding Path=FirstName}" IsReadOnly="True"/>
    </DataGrid.Columns>
</DataGrid>

The Person class has properties LastName and FirstName (amoung others). As I understand it, if the ObservableCollection itself changes – like what I do by clearning and filling it back up, it should automatically fire the INPC event, but my DataGrid doesn’t seem to refresh the second time around. Any ideas would be really helpful.

Thanks!

*EDIT*
Here’s how I wound up solving the problem:

Public Shared Property CoreInfoData() As ObservableCollection(Of Person)

Public Shared Property CoreInfoData() As ObservableCollection(Of Person)
    Get
        Return _coreInfoData
    End Get
    Set(ByVal value As ObservableCollection(Of Person))
        If _coreInfoData Is Nothing Then
            'get data
             _coreInfoData = value
        Else
             'refresh data
             _coreInfoData.Clear()
              For i = 0 To value.Count - 1
                    _coreInfoData.Add(value(i))
              Next
        End If
    End Set
End Property

The First time the Set Method is called it will create a new _coreInfoData variable. Subsequent calls will replace the existing one by clear it’s entire contents and looping through each item to add it back into the collection.
Thanks to Clemens, Dan Busha, and Charleh (and others) for their helpful comments!

  • 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-06-09T06:41:33+00:00Added an answer on June 9, 2026 at 6:41 am

    No PropertyChanged event will be raised automatically simply because the type of a property is ObservableCollection. You would have to raise it in the setter:

    Set(ByVal value As ObservableCollection(Of Person)) 
        _coreInfoData = value
        OnPropertyChanged("CoreInfoData")
    End Set 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,

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.