I'm pretty new to MAUI, and i'm working on a simple CRUD-App to get into it. Now I have all the functions implementet, but now when I linked the AddUpdateObject()
function to the submit button, it says that this function doesn't exist
This is my XAML:
<StackLayout Margin="10" Spacing="20">
<VerticalStackLayout Margin="10">
<Label Text="Name" FontSize="16"/>
<Entry Text="{Binding Name}" Placeholder="Name"/>
<BoxView HeightRequest="0.8" Color="Gray"/>
</VerticalStackLayout>
<Button Text="Save" Command="{Binding AddUpdateObject}" />
</StackLayout>
This is my Code-Behind:
using project.ViewModels;
namespace project.Views;
public partial class AddObjectAlbumDetail : ContentPage
{
public AddUpdateAlbumDetail(AddUpdateObjectDetailViewModel viewModel)
{
this.BindingContext = viewModel;
InitializeComponent();
}
}
And this is my AddUpdateObject()
function in AddUpdateObjectDetailViewModel
:
[ObservableProperty]
private string _name;
[ICommand]
public async void AddUpdateObject()
{
var response = await _objectService.AddObject(new Models.TestModel
{
Name = Name,
//ReleaseDate=Date,
}) ;
if(response > 0)
{
await Shell.Current.DisplayAlert("Created", "Object Created!", "OK");
}
else
{
await Shell.Current.DisplayAlert("Not Created", "Something went wrong while creating", "OK");
}
}
I'm sure the model is right since it only contains 1 attribute (string) and an auto incrementing id.
Thanks in advance
CodePudding user response:
The [ICommand] is [RelayCommand] now.
The InitializeComponent is called first.
The command is bound by {Binding AddUpdateObjectCommand} not AddUpdateObject.