Wpf textblock binding not updating


Dynamically Updating Items is Problematic Ideally, applying a sort order to a Collection View would result in a grouped and sorted view of the collection that is fully maintained even when items within the collection are changed.Unfortunately, a List Collection View only groups and sorts its items when the view is first created (or when new items are added to the source collection, assuming that the source collection is observable).Each item is drawn using a Button, and the Button’s Command property is bound to the Change Page Command.

For one, all my Page View Models now inherit from an IPage View Model interface so they can have some common properties, such as a Name.

I also created a new Home View Model and Home View since its hard to demonstrate navigation unless you have at least 2 pages.

Run the project and you should see something that looks like the images below, which quickly switches the Current Page when clicking on the Navigation buttons. Once you get more comfortable with WPF, I would recommend looking into using a Messaging System, such as MVVM Light’s Messenger, or Microsoft Prism’s Event Aggregator to broadcast Change Page commands from any View Model so you wouldn’t need to find the Application View Model to execute the Change Page Command, however that’s for another day.

Whilst having an Observable Collection of “Person” objects, and creating a collectionview for this and also adding a Sort Description on a “Name” property on the “Person” object, I noticed that if I change the “Name” property on one of the objects (they are shown in a listbox, having the “Name” property databound to a textblock), and thereafter calling Refresh() on the Collection View, the refresh will actually take more than a second with only about 50 items.

I know that my Window is the Application View, and it’s Data Context is the Application View Model, so this binding looks up the Visual Tree for the Window tag, and gets bound to Window. Resources to tell WPF how to draw each IPage View Model.