How to use binding in .Net Maui?
21:52 07 Mar 2023

I'm creating a custom view in .Net Maui 7 as follows:

XAML:




            
        ... something               
    

C#

public partial class MyView : Grid
{        
    MyViewVM myViewVM;
    
    public MyView()
    {
        InitializeComponent();

        this.myViewVM = new MyViewVM();                        
    }
}

View Model in C#

public partial class MyViewVM : ObservableObject
{
    [ObservableProperty]        
    bool started;       
}

The view is supposed to be added to other pages or other custom views. So I can't use the property binding context for the binding:

this.BindingContext = this.myViewVM;    // I don't want to use that

So I'm adding binding properties in XAML as follows:


When changing the binding property value (in this case named Started) nothing happens to the label added. while it's supposed to be invisible when the property Started is false.

What am I doing wrong?

c# maui