Click here to Skip to main content
15,899,023 members
Home / Discussions / WPF
   

WPF

 
GeneralRe: WPF Update UI When Collection Changes Pin
SledgeHammer011-Aug-12 15:49
SledgeHammer011-Aug-12 15:49 
GeneralRe: WPF Update UI When Collection Changes Pin
Kevin Marois1-Aug-12 17:33
professionalKevin Marois1-Aug-12 17:33 
GeneralRe: WPF Update UI When Collection Changes Pin
SledgeHammer011-Aug-12 17:46
SledgeHammer011-Aug-12 17:46 
GeneralRe: WPF Update UI When Collection Changes Pin
Kevin Marois2-Aug-12 13:39
professionalKevin Marois2-Aug-12 13:39 
GeneralRe: WPF Update UI When Collection Changes Pin
SledgeHammer012-Aug-12 14:08
SledgeHammer012-Aug-12 14:08 
GeneralRe: WPF Update UI When Collection Changes Pin
Pete O'Hanlon1-Aug-12 22:13
mvePete O'Hanlon1-Aug-12 22:13 
GeneralRe: WPF Update UI When Collection Changes Pin
Kevin Marois2-Aug-12 6:31
professionalKevin Marois2-Aug-12 6:31 
GeneralRe: WPF Update UI When Collection Changes Pin
Gerry Schmitz2-Aug-12 8:40
mveGerry Schmitz2-Aug-12 8:40 
There is no “rule” that says each property must raise its own property changed event.

Here's a class where I used reflection to raise the event for all properties in a class after performing an update.

(I call "Notify" anytime I've updated some "stats"; I consider the overhead of calling the event for any properties that did not change insignificant).

C#
using System;
using System.ComponentModel;
using System.Reflection;

namespace ModbusProtocol {

   //---------------------------------------------
   // Class for capturing serial port statistics.
   //---------------------------------------------
   public class ComPortStats : INotifyPropertyChanged {

      public event PropertyChangedEventHandler PropertyChanged;

      private PropertyInfo[] _pInfo;

      //-----------------------------------------------
      // Stats.
      //-----------------------------------------------
      public int WriteRequests { get; set; }
      public int Writes { get; set; }
      public long BytesWritten { get; set; }
      public int WriteErrors { get; set; }

      public int ReadRequests { get; set; }
      public int Reads { get; set; }
      public long BytesRead { get; set; }
      public int ReadNoReply { get; set; }
      public int ReadTimeouts { get; set; }
      public int ReadErrors { get; set; }

      // Updated from FunctionBase.
      public int CRCReadErrors { get; set; }

      //---------------------------------------------
      // Constructor.
      //---------------------------------------------
      public ComPortStats() {

         // Retrieve property names.
         Type objectType = this.GetType();

         _pInfo = objectType.GetProperties(
            BindingFlags.Public | BindingFlags.Instance );
      }

      //---------------------------------------------
      // Notify subscribers that "all" changed.
      //---------------------------------------------
      public void Notify() {

         foreach ( PropertyInfo p in _pInfo ) {

            OnPropertyChanged( p.Name );

         }  // end foreach.
      }

      //---------------------------------------------
      // Property changed event handler / notification.
      //---------------------------------------------
      protected void OnPropertyChanged( string name ) {

         if ( PropertyChanged != null ) {
            PropertyChanged( this, new PropertyChangedEventArgs( name ) );
         }
      }

   }  // end class.

}  // end namespace.

GeneralRe: WPF Update UI When Collection Changes Pin
Kevin Marois2-Aug-12 8:47
professionalKevin Marois2-Aug-12 8:47 
GeneralRe: WPF Update UI When Collection Changes Pin
Gerry Schmitz2-Aug-12 9:05
mveGerry Schmitz2-Aug-12 9:05 
GeneralRe: WPF Update UI When Collection Changes Pin
Ed Hill _5_2-Aug-12 23:02
Ed Hill _5_2-Aug-12 23:02 
GeneralRe: WPF Update UI When Collection Changes Pin
Pete O'Hanlon2-Aug-12 9:47
mvePete O'Hanlon2-Aug-12 9:47 
GeneralRe: WPF Update UI When Collection Changes Pin
Gerry Schmitz2-Aug-12 9:55
mveGerry Schmitz2-Aug-12 9:55 
GeneralRe: WPF Update UI When Collection Changes Pin
Kevin Marois2-Aug-12 9:57
professionalKevin Marois2-Aug-12 9:57 
GeneralRe: WPF Update UI When Collection Changes Pin
Pete O'Hanlon2-Aug-12 10:21
mvePete O'Hanlon2-Aug-12 10:21 
GeneralRe: WPF Update UI When Collection Changes Pin
Kevin Marois2-Aug-12 10:25
professionalKevin Marois2-Aug-12 10:25 
GeneralRe: WPF Update UI When Collection Changes Pin
Kevin Marois2-Aug-12 10:02
professionalKevin Marois2-Aug-12 10:02 
GeneralRe: WPF Update UI When Collection Changes Pin
Kevin Marois2-Aug-12 9:56
professionalKevin Marois2-Aug-12 9:56 
GeneralRe: WPF Update UI When Collection Changes Pin
Gerry Schmitz2-Aug-12 10:33
mveGerry Schmitz2-Aug-12 10:33 
GeneralRe: WPF Update UI When Collection Changes Pin
Kevin Marois2-Aug-12 10:43
professionalKevin Marois2-Aug-12 10:43 
GeneralRe: WPF Update UI When Collection Changes Pin
SledgeHammer012-Aug-12 12:58
SledgeHammer012-Aug-12 12:58 
GeneralRe: WPF Update UI When Collection Changes Pin
Kevin Marois2-Aug-12 13:01
professionalKevin Marois2-Aug-12 13:01 
GeneralRe: WPF Update UI When Collection Changes Pin
SledgeHammer012-Aug-12 13:20
SledgeHammer012-Aug-12 13:20 
GeneralRe: WPF Update UI When Collection Changes Pin
Kevin Marois2-Aug-12 13:27
professionalKevin Marois2-Aug-12 13:27 
GeneralRe: WPF Update UI When Collection Changes Pin
SledgeHammer012-Aug-12 13:31
SledgeHammer012-Aug-12 13:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.