Forum Xamarin.Forms

Binding to a toolbar button not working

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


        <ToolbarItem x:Name="btnOk" Text="OK" Command="{Binding SaveCommand}"/>

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?


Best Answer


  • Xami3Xami3 PKMember, University ✭✭✭

    are you assigning the VM to whole page bindingContext or to the content's binding context ?

  • QuantivQuantiv Member ✭✭

    Thanks for your replies. It took a little while, but then we realized that we used the wrong binding context and the wrong page type. We had been working with ContentViews instead of ContentPages. Now, everything is fine :-)

Sign In or Register to comment.