Search code examples
c#maui

MAUI Bindable Property


     private static readonly BindableProperty InstanceProperty = 
     BindableProperty.Create(nameof(Instance), 
     typeof(MenuManagerViewModel), typeof(MenuView),
     null, propertyChanged: InstancePropertyChanged);

    private static void InstancePropertyChanged(BindableObject bindable, object oldValue, object newValue)
    {
    }
    
    public MenuManagerViewModel Instance
    {
        get => (MenuManagerViewModel)GetValue(InstanceProperty);
        set => SetValue(InstanceProperty, value);
    } 


    public MenuManagerViewModel Menu { get; }          
    public MainManagerViewModel Main { get; }          
    Public FootManagerViewModel Foot { get; }


     <views:MenuView Grid.Row="0" Instance="{Binding ViewManager.Menu, Mode=OneWay}"/>
     <views:MainView Grid.Row="1" Instance="{Binding ViewManager.Main, Mode=OneWay}"/>         
     <views:FootView Grid.Row="2" Instance="{Binding ViewManager.Foot, Mode=OneWay}"/>

Iknow about the pattern in the docs with naming convertions but why is this still not working

Dont seeing my error at all. Expecting it to work :D


Solution

  • As the doc says,

    A bindable property can be created by declaring a public static readonly property of type BindableProperty.

    So you should use

    public static readonly BindableProperty InstanceProperty = ...
    

    instead of private static readonly

    For more info, please refer to Create a bindable property.