.Net Maui Validate Property of a Model in the ViewModel Class

Tom Meier 220 Reputation points
2024-07-08T19:52:09.4566667+00:00

I am using MVVM along with the MVVM Community Toolkit.

I have a Constructor in my .Net Maui ViewModel

public EmployeeEditViewModel()
{
	CompanyInfo= new PYEModel();
}

I have an Observable property in the .Net Maui ViewModel

[ObservableProperty]
PYEModel _companyInfo;

These events are in the Code Generated Community Toolkit.

OnCompanyInfoChanging

OnPropertyChanging

OnCompanyInfoChanged

OnPropertyChanged

For some reason I can't get any of these events to fire when I change a property of the CompanyInfo Observable Property.

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,207 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,627 questions
0 comments No comments
{count} votes

Accepted answer
  1. Bruce (SqlWork.com) 61,186 Reputation points
    2024-07-08T20:46:25.6966667+00:00

    _companyInfo will only fire an event, if you change the object reference, not if you change any of its properties. you need to change the PYEModel class to an observable object whose properties you can bind to.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful