Toolbar Command Binding Problem Xaml

S_Olias_SS_Olias_S DEMember ✭✭
edited March 2016 in Xamarin.Forms

Hey,
i´m trying to Bind a toolbaritem but unfortunatly, when i press "Add" nothing happens.

<ContentPage.ToolbarItems>

<ToolbarItem Text="Add" Command="{Binding AddTicketCommand}" />

</ContentPage.ToolbarItems>

public Toolbartest(){
     AddTicketCommand = new Command(GotoAddTicket);
    }
    public ICommand AddTicketCommand { set; get; }

    private async void GotoAddTicket()
    {
        await navigation.PushModalAsync(new AddTicketPage());
    }

Best Answer

Answers

  • JulienRosenJulienRosen CAMember ✭✭✭✭

    Examine your output window for binding errors at runtime. From the code you posted, it doesn't look like you are assigning a BindingContext. Your page that contains the ToolbarItem needs to have as its BindingContext an instance of a class that has the AddTicketCommand.

  • S_Olias_SS_Olias_S DEMember ✭✭
    edited March 2016

    Sry i forgot to add this to the question.
    Her you can see how i Bind the ViewModel.
    <ContentPage .....

            xmlns:AppName="clr-namespace:AppName.ViewModel">
    

    <ContentPage.Resources>
    *ResourceDictionary>
    *AppName:Toolbartest />
    */ResourceDictionary>
    </ContentPage.Resources>

    *< deltete because of the website....

  • JulienRosenJulienRosen CAMember ✭✭✭✭

    That is not how you bind anything at all.

    Generally I do it in the constructor of my page
    BindingContext = new MyViewModel();

Sign In or Register to comment.