Binding ToolbarItems

CheesebaronCheesebaron DKInsider, University mod

I am attempting to bind a ToolbarItem with:

var aboutItem = new ToolbarItem {Name = "About"};
aboutItem.SetBinding(ToolbarItem.CommandProperty, new Binding("ShowAboutPageCommand"));
ToolbarItems.Add(aboutItem);

The command looks like:

    public ICommand ShowAboutPageCommand
    {
        get
        {
            return new MvxCommand(() => ShowViewModel<AboutViewModel>());
        }
    }

If I for instance bind that command to a button instead it works fine, however nothing happens when I press the item in the ActionBar on Android.

Posts

  • ChaseFlorellChaseFlorell CAInsider, University mod

    Not an answer to your question, but that's an interesting mix of X.Forms and Mvx. How are you finding the marriage?

    On our new X.Forms app, we've removed Mvx and haven't really missed it (yet).

  • CheesebaronCheesebaron DKInsider, University mod

    This is for a sample application I am making. However, a lot of stuff such as all the plugins for MvvmCross are still very useful in the mix, and I really like that I don't have to roll my own Mvvm framework.

  • rmarinhormarinho PTMember, Insider, Beta Xamurai

    @Cheesebaron‌ for what i know there's a problem where toolbaritems aren't getting the bindingcontext, that should be fixed in the next version

  • ChaseFlorellChaseFlorell CAInsider, University mod
    edited June 2014

    Might be a long shot, but doesn't your ToolBarItem also need a BindingContext?

    edit

    or what @rmarinho said :)

  • rmarinhormarinho PTMember, Insider, Beta Xamurai

    yeah , that's the problem it should be getting the same as the page but it's a bug and it doesn't .

  • CheesebaronCheesebaron DKInsider, University mod
    edited June 2014

    @ChaseFlorell‌, @rmarinho‌ Doing:

    var aboutItem = new ToolbarItem {Name = "About", BindingContext = BindingContext};
    aboutItem.SetBinding(ToolbarItem.CommandProperty, new Binding("ShowAboutPageCommand"));
    

    Does not do any difference. What do I set BindingContext to?

  • CheesebaronCheesebaron DKInsider, University mod

    OK so It seems that where I am creating the ToolbarItem the BindingContext is null (ctor), so I probably have to move that code elsewhere.

  • rmarinhormarinho PTMember, Insider, Beta Xamurai
    edited June 2014

    i now this isn't very good , but can you try:

    var aboutItem = new ToolbarItem {Name = "About", BindingContext = App.MyViewModel};

    When are you setting the ViewModel, you can try to put your code on OnAppearing too

  • CheesebaronCheesebaron DKInsider, University mod

    I put it into OnBindingContextChanged, works now :)

  • rmarinhormarinho PTMember, Insider, Beta Xamurai

    :) cool!

  • EricMaupinEricMaupin USXamarin Team Xamurai

    Just FYI: There's a bug that's been fixed for the next update that ToolbarItem does not correctly inherit it's BindingContext.

  • ChaseFlorellChaseFlorell CAInsider, University mod

    @ermau, it sounds like there are a few nice fixes in the next update. Do you happen to have an ETA?

  • EricMaupinEricMaupin USXamarin Team Xamurai

    @ChaseFlorell‌ How about now? It's out!

  • ChaseFlorellChaseFlorell CAInsider, University mod
    edited June 2014

    Nice, just updated!

    Frig I have issues updating Nuget Packages in VS2013 with Resharper...

    1. I have to disable R# to prevent some randoms errors in the update
    2. When I update, it drops the files in the packages folder, but when I build, it fails to see Xamarin. To fix I have to "Manage Packages" and remove them and re-add them... so frustrating.
  • Please write full code how to binding toolbaritems. I have the same problem

  • vishal.2562vishal.2562 USMember

    @Cheesebaron @IbrahimSusic Please update the Toolbaritems. I have same problem.

  • @vishal.2562 What is the problem ?

Sign In or Register to comment.