For some context, I'm using Microsoft's MVVM Toolkit and .Net Maui.
Im trying to bind a RelayCommand to a Command Bindable object of a view. The code builds fine, it's at runtime that I'm seeing the following error: "Warning: 'DeleteCommand' property not found on 'MyApp.PageModels.MainPageModel', target property: 'MyApp.Views.NavigationBar.RightButtonCommand'"
Here's the code:
MainPage.xaml
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:pageModels="clr-namespace:MyApp.PageModels"
xmlns:views="clr-namespace:MyApp.Views"
NavigationPage.HasNavigationBar="False"
BackgroundColor="#4044C9"
x:Class="MyApp.Pages.MainPage"
x:DataType="pageModels:MainPageModel" >
<StackLayout>
<views:NavigationBar
Title="{Binding Total, StringFormat='{0:C}'}"
RightButtonImageSource="add"
RightButtonCommand="{Binding DeleteCommand}"/>
<!-- Other code -->
</StackLayout>
</ContentPage>
MainPageModel.cs
public partial class MainPageModel : ObservableObject
{
[ObservableProperty]
double total;
[RelayCommand]
async Task Delete()
{
//execute delete
}
}
NavigationBar.xaml.cs
public partial class NavigationBar : ContentView
{
// BindableProperty for the right image button's command
public static readonly BindableProperty RightButtonCommandProperty =
BindableProperty.Create(nameof(RightButtonCommand), typeof(Command), typeof(NavigationBar), default(Command), BindingMode.OneWayToSource);
// Right button command property
public Command RightButtonCommand
{
get => (Command)GetValue(RightButtonCommandProperty);
set => SetValue(RightButtonCommandProperty, value);
}
}
I binded the variable Total to the view's Label and it show without problems. The issue is with the RelayCommand DeleteCommand.