1

So, I am trying to experiment with .NET Maui and wanted to use the community toolkit for MVVM. Here is the extremely simple class:

using CommunityToolkit.Mvvm.ComponentModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MauiApp2
{
    public partial class Class1 : ObservableObject
    {
        [ObservableProperty]
        public int test;

        [ObservableProperty]
        [NotifyPropertyChangedFor(nameof(Test))]
        public int test2;

        public void Testing()
        {
            Test = 1;
        }
    }
}

And here is what the source generator is showing, the MVVM is not throwing any errors in the code but see here.

screen grab

Any ideas what's causing this?

I have searched every way I can think of and I haven't seen anything about these issues.

Julian
  • 5,290
  • 1
  • 17
  • 40
  • Are you actually experiencing any issues? Do the source generators not work or are you just asking about those messages under the analyzers? Generally, the MVVM Source Generators work well with MAUI as they're independent of the UI framework. When you open the *ObservablePropertyGenerator*, can you find the generated classes there? If you do, then nothing is wrong. – Julian Mar 25 '23 at 14:36
  • Yes, the INotifyPropertyChanged is not working. I have a view with the test fields binded and no updating .... on the screen grab if you look under the INotifyPropertyChangedGenerator it shows not generating??? – Larry Gragg Mar 25 '23 at 14:40
  • That's the wrong generator. You should be looking for the **ObservablePropertyGenerator** instead, because that's what `[ObservableProperty]` uses. Please add the relevant XAML where you try to bind to the properties to the question. – Julian Mar 25 '23 at 14:42
  • Per your snippet code, I can't reproduce your error. May I know your version of `Community.Toolkit.MVVM`? Also, as peter suggested, you should be looking for the `ObservablePropertyGenerator `instead. Last but not least, if possible, Could you please create a [Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example) via github repo link? – Alexandar May - MSFT Mar 27 '23 at 07:11
  • @LarryGragg MVVM is working, more than fine. I do not see your View code and XAML. I need to see 3 things, the place you set your Binding context, the place you set {Binding Text}, and the call of your Testing() method. – H.A.H. Mar 27 '23 at 11:44

0 Answers0