Hi there,
i have a problem with a toolbar button and its binding.
First, I have created some entries and a button to save the users input.
Class AddReportPage
<Button Text="OK" Command="{Binding SaveCommand}"></Button>
The button is working as expected.
But I want to save the data by hitting a button in the toolbar instead. So I put a toolbar item into my CustomPage, which includes the basic layout for all my pages.
Class AddSystemPage : CustomPage
XAML:
<local:CustomPage.ToolbarItems>
<ToolbarItem x:Name="btnOk" Text="OK" Command="{Binding SaveCommand}"/>
</local:CustomPage.ToolbarItems>
For any reason, the binding of the SaveCommand to the toolbar item is not working.
I tried to do the binding in the ViewModel like this:
Class AddReportViewModel : BindableBase, INavigationAware, INotifyPropertyChanged
public AddReportViewModel()
{
SaveCommand = new Command(Save, CanSave);
}
public Command SaveCommand { get; set; }
private void Save()
{
var item = new ReportItem()
{
subject = Title,
description = Body,
created = DateTime.Now
};
// save the item to database ...
}
private bool CanSave()
{
return !string.IsNullOrEmpty(Title) && !string.IsNullOrEmpty(Body);
}
The toolbar item is definitely existing - but the command will not be executed.
Can anyone help me please?