C# grid binding not update

前端 未结 3 807
醉话见心
醉话见心 2021-01-22 09:37

I have a grid that is binded to a collection. For some reason that I do not know, now when I do some action in the grid, the grid doesn\'t update.

Situation : When I cli

3条回答
  •  孤街浪徒
    2021-01-22 10:12

    In order for the binding to be bidirectional, from control to datasource and from datasource to control the datasource must implement property changing notification events, in one of the 2 possible ways:

    • Implement the INotifyPropertyChanged interface, and raise the event when the properties change :

      public string Name 
      {
        get
        {
          return this._Name;
        }
        set
        {
          if (value != this._Name)
          {
              this._Name= value;
              NotifyPropertyChanged("Name");
          }
        }
      }
      
    • Inplement a changed event for every property that must notify the controls when it changes. The event name must be in the form PropertyNameChanged :

      public event EventHandler NameChanged;
      
      public string Name 
      {
        get
        {
          return this._Name;
        }
        set
        {
          if (value != this._Name)
          {
              this._Name= value;
              if (NameChanged != null) NameChanged(this, EventArgs.Empty);
          }
        }
      }
      

      *as a note your property values are the correct ones after window maximize, because the control rereads the values from the datasource.

提交回复
热议问题