Quantcast
Viewing latest article 1
Browse Latest Browse All 3

WPF datagrid

First of all you need to turn the name and val fields of your class into properties. Then you have to raise the PropertyChanged event for these properties whenever you set them to some new value:

 public class Sample : INotifyPropertyChanged
    {

        int name;
        public int Name { get { return name; } set { name = value; NotifyPropertyChanged("Name"); } }

        int val;
        public int Val { get { return val; } set { val = value; NotifyPropertyChanged("Val"); } }

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

        public event PropertyChangedEventHandler PropertyChanged;
    }

With this changes in place, the values in the view will get automatically updated when you dynamically change a property of a Sample object provided that you have set up the binding correctly:

<TextBlock Text="{Binding Name}" />

For the binding to work, the DataContext of the bound UI element must be set to your list of Sample objects or to the individual Sample object that you are updating dynamically.

Please refer to the following link for more information about the INotifyPropertyChanged interface and how to implement it and use it: http://msdn.microsoft.com/en-us/library/system.componentmodel.inotifypropertychanged(v=vs.110).aspx


Viewing latest article 1
Browse Latest Browse All 3

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>