Share via

Tracking my Model in Watch Window

Anonymous
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 !!!!

Developer technologies | .NET | .NET MAUI
0 comments No comments

Answer accepted by question author
  1. Anonymous
    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

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.