Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a line separator between Page.Toolbaritems in Xamarin Forms

I'm adding toolbar item to the Page.ToolbarItems list, but I would like to add a line separator between certain toolbar item. I could add a new toolbar item with an image of a line, but I would need to prevent any Action when the line is pressed and it won't allow me to use null. It would also look less than ideal.

Note that that each ToolbarItem is added through the C# code, not through Xaml.

Here is some pseudo code as an example of what I have now:

if(!ToolbarItems.Any())
{
    ToolbarItems.Add(new ToolbarItem("Page 1", null, NavigateToPage1(), ToolbarItemOrder.Secondary, 0);
    ToolbarItems.Add(new ToolbarItem("Page 2", null, NavigateToPage2(), ToolbarItemOrder.Secondary, 0);
    // <Insert Separator Here>
    if(boolVal) {
        ToolbarItems.Add(new ToolbarItem("Page 3", null, NavigateToPage3(), ToolbarItemOrder.Secondary, 0); 
    }
    ToolbarItems.Add(new ToolbarItem("Page 4", null, NavigateToPage4(), ToolbarItemOrder.Secondary, 0);
    ToolbarItems.Add(new ToolbarItem("Page 5", null, NavigateToPage5(), ToolbarItemOrder.Secondary, 0);
    // <Insert Separator Here>
    ToolbarItems.Add(new ToolbarItem("Page 6", null, NavigateToPage6(), ToolbarItemOrder.Secondary, 0);
}
like image 927
J. Ha Avatar asked Apr 23 '18 17:04

J. Ha


1 Answers

Strictly speaking, you can't.

ToolbarItems map to specific controls in iOS and Android which don't provide the capability that you want to have, so even if you go into writing the custom renderers it is not possible because native platforms don't allow this.

Speaking a bit more widely if you use TitleView then you can put into the header whatever you want and then you can make it look like what you wanted but that isn't a precise answer to your question as you wouldn't use ToolbarItems in that case.

like image 176
Ivan Ičin Avatar answered Oct 22 '22 15:10

Ivan Ičin