Forum Xamarin.Forms

Left toolbaritems in Xamarin Forms

EllenKEllenK USMember ✭✭

Summary

Currently we can not place toolbaritems on the left side, on default. It's possible to write a renderer for the ContentPage on ios (see https://timeyoutake.it/2016/01/02/creating-a-left-toolbaritem-in-xamarin-forms/).
But it would be nice if we can place toolbaritems on the left on default.

API Changes

In order to place a toolbaritem on the left, a property is added to the ToolbarItem class:

ToolbarItem toolbarItem = new ToolbarItem(); toolbarItem.Position = ToolbarItemPosition.Left;

public enum ToolbarItemPosition { Left, Right }

where ToolbarItemPosition.Right is the default.

Intended Use Case

We can use this in every situation where you want a toolbarItem on the left side. A very common situation is a detailpage with "Cancel" on the left side and "Save" on the right side:

Tagged:

Rejected · Last Updated

Posts

  • EllenKEllenK USMember ✭✭

    @JohnMiller said this is the right place to bring this up.

  • seanydaseanyda GBMember ✭✭✭✭✭

    This would be nice but I don't think anything like this exists in Android or Windows natively? I might be wrong.

  • EllenKEllenK USMember ✭✭
    edited December 2016

    On Windows not so much I think, but on android this would be nice. For example to position everything on the left:

    Or imagine an app where you want a detail screen without backbutton and you want to separate the toolbar items on functionality without using a submenu. For example in a text editor screen:
    [TextColor button][FontSize button]-------------[Cancel][Save]
    I have an app on my phone that does that.

  • PaulDiPietroPaulDiPietro USXamarin Team Xamurai

    It can technically be done on UWP, but UWP uses CommandBar as its standard control (the documentation recommends it be used with new UWP apps) which does not provide the fine tooling which AppBar does in terms of alignment, so doing so goes against the regular UI structure. Alternatively we could use a single AppBarSeparator to split left and right items in UWP, but they would still be right-aligned; we'd also have to consider whether any future platforms that might be supported would be able to use this, which they may not.

    I think the best option would be to provide platform specific features for one or both of iOS and Android, were this to be implemented.

  • AdamMeaneyAdamMeaney USMember ✭✭✭✭✭

    If you make it platform specific, it kind of ruins the point of most of this.

    If you want to do what the OP describes as the most common use case of this, the picture he posted, having to redo the UWP one with some random custom bar or logic does not help the situation.

  • PierceBogganPierceBoggan USForum Administrator, Xamarin Team, Developer Group Leader Xamurai

    I don't think having this as a platform-specific configuration is too big a deal. You can still do this from shared code, and instead of perhaps one line of code like so:

    toolbarItem.Position = ToolbarItemPosition.Left

    It would only be one more line of code to do with a platform-specific:

    toolbarItem.On<Xamarin.Forms.PlatformConfiguration.Android>().ToolbarItemPosition = ToolbarItemPosition.Left;
    toolbarItem.On<Xamarin.Forms.PlatformConfiguration.iOS>().ToolbarItemPosition = ToolbarItemPosition.Left;
    

    I don't think this adds any pain in terms of development, and it encourages developers to follow the UX paradigms the underlying platforms offer. I think this is a great case for platform-specifics :smile:

  • JamesMontemagnoJamesMontemagno USForum Administrator, Xamarin Team, Developer Group Leader Xamurai
    This would make sense to be a platform specific effect. It technically is doable on Android if you use a custom toolbar, but would be a bit anti-pattern to me.
  • EllenKEllenK USMember ✭✭

    I also would be very happy with the solution @pierce.boggan is giving.

  • NMackayNMackay GBInsider, University admin

    @pierce.boggan solution makes the most sense and is a feature we asked for back in 2015 so would be cool if it was added using this approach.

  • rmarinhormarinho PTMember, Insider, Beta Xamurai

    We also think this should be a platform specific.

This discussion has been closed.