How to include a new right icon in an Activity Xamarin Forms

Asked

Viewed 403 times

1

It is possible to include a new icon in a activity but the right, without changing the existing ?

I need to include the user photo on the right.

(Red spot on image)

Imagery:

inserir a descrição da imagem aqui

2 answers

2

A way would be like this:

<ContentPage.ToolbarItems>
        <ToolbarItem Text="Usuario" Order="Primary" Priority="0">
            <ToolbarItem.Icon>
                <OnPlatform x:TypeArguments="FileImageSource"
                    WinPhone="Toolkit.Content/imagem.png"
                    Android="imagem.png"
                    iOS="imagem.png"
                    />
            </ToolbarItem.Icon>
        </ToolbarItem>
    </ContentPage.ToolbarItems>

1


It is possible yes, to do this you need to add a new "Toolbaritem" to your taskbar. If you are developing the page directly in C# you can do as follows

this.ToolbarItems.Add(new ToolbarItem("nome", "icone", () => 
        {
            // ação ao clicar no icone
        }, ToolbarItemOrder.Primary));

Where:

  • The "name" would be the name to appear when the user pressed and held the icon, or if there is no icon image, in which case the text is spelled.

  • The "icon" would be the icon you will use for the option, in this case the user image

  • The lambid expression "() => { //code here }" would serve to perform some action by clicking on the icon (aka. User photo =P )

  • And the "Toolbaritemorder.Primary" serves to indicate the position that the item will be in the menu, if you put "Toolbaritemorder.Secondary" the item will be in an options menu (The same place you usually find the "Settings" of an app, that menu with three dots "...")already if you put "Toolbaritemorder.Primary" it will show up as an item in the menu, showing the icon you set to it or the user photo in your case =)

I hope I’ve helped =)

  • Where do I add this new Toolbaritem ? In Activity ?

  • Exactly, in the example, I am creating my screen directly by code, that is, I do not have the layout XAML, then I add it to the class builder, which I inherit from Contentpage

  • can, just do not know now how to display the image there without Image. Good Tips ?

  • The user image will be saved on the Device or it will be downloaded from the internet?

  • I’m returning her from the comic to a property. I can’t use this property to display the photo ?

  • Huuum, you return the entire BD image or Path to it on the device?

  • maybe if you change the image property of the object "Toolbaritem" and indicate the file you want to show may be possible, but I can’t tell you for sure, because I never did it this way =\

  • I tried to do it but it didn’t work. hehe. tranquil. thanks

  • Nothing, in case you reach a solution post the answer here, it will be nice to know how you arrived at it =D

Show 4 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.