skip to content »

fidiff.nnkstudio.ru

Wpf datagrid binding not updating

Since the title of this post says to use a List Box, that is what we will use.

The example uses a typical Model-View-Controller architecture.

Description: Imagine receiving the task of displaying some array of objects.

The controller class will begin small and only contain the array of Class Info objects. Class Controller.cs: Thinking about this for a moment, it seems we are going to want to display this data somehow. (in this case “Class View.”) See below for the XAML, the code behind is simply default for now.

Class View.xaml: Class View is the “View”, and Class Controller is the “Controller” in the MVC architecture.

Moving forward, in order for Class Controller to modify the correct Class Model object, Class View will have to give its instance of Class Model to Class Controller.

wpf datagrid binding not updating-54

Class View’s definition will change to the following.

For now it will only hold the name of a particular class.One approach would be to iterate over the array and perform a “to String” on each object outputting the concatenation of all strings. Sure, if what needs to be displayed changes you can simply update the respective object’s to String implementation and be done.However, if the object has changed such that representing it by a simple string is not descriptive enough, then there is a big problem.When you setup data binding it appears that if the object being bound to implements this interface it is automatically used Class Model.cs: Alright! This is okay except that I think we would rather see the data which distinguishes the objects from each other.So we have a problem with the way these objects are being displayed.We’ll use an Observable Collection in the model class so that Class View can bind directly to the property. Class Model.cs: Next, we know that Class View will have to bind to and display this property.