Tracking my Model in Watch Window

Ronald Rex 141 Reputation points
2022-12-23T22:30:40.4+00:00

I was wondering what is best practice for instantiating a Model in your ViewModel class for purposes of adding it to the watch window so that you can see your Model Properties change while the application runs in debug mode. Thanks !!!!

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
913 questions
No comments
{count} votes

Accepted answer
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 41,831 Reputation points Microsoft Employee
    2022-12-26T05:59:51.113+00:00

    Hello,

    Do you implement the INotifyPropertyChanged in your Model?

    If so, you can add Console.WriteLine(value); in get/set method of properties. When you debug your application, you can see the value changes of properties of Model in output Window.

       public class MyModel : INotifyPropertyChanged  
       {  
           double hue;  
             
          public event PropertyChangedEventHandler PropertyChanged;  
         
          public double Hue  
           {  
               set  
               {  
                   if (hue != value)  
                   {  
                       hue = value;  
                       OnPropertyChanged("Hue");  
                       Console.WriteLine("Hue:   " + value);  
                   }  
               }  
               get  
               {  
                   return hue;  
               }  
           }  
           protected virtual void OnPropertyChanged(string propertyName)  
           {  
               PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));  
           }  
       }  
    

    Best Regards,

    Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful