如何在Xamarin Forms应用程序的导航栏中添加照片

时间:2019-04-28 02:34:15

标签: xamarin xamarin.forms

如何在导航中添加照片。在单击照片时,应导航到编辑用户屏幕。我使用的是选项卡式页面设计,Home, Map and Settings是我的选项卡式页面。

enter image description here

1 个答案:

答案 0 :(得分:1)

您可以使用ToolbarItems在导航栏的右侧添加图标

<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="TabPageSample.Views.MyTabbedPage">
    <TabbedPage.ToolbarItems>
        <ToolbarItem Icon="profileicon.png" Clicked="OnProfilePicClicked"/>
    </TabbedPage.ToolbarItems>
    <ContentPage Title="HOME" />
    <ContentPage Title="MAP" />
    <ContentPage Title="SETTINGS" />
</TabbedPage>

在页面的后端类中添加事件:

private void OnProfilePicClicked(object sender, EventArgs e)
{
    //Navigate to Edit Profile page here
}

PS:以编程方式:

var tabbedPage = new TabbedPage(); 
tabbedPage.Children.Add(new Home()); 
tabbedPage.Children.Add(new Map()); 
tabbedPage.Children.Add(new Settings());

//Create Toolbar Item
var profilePicTollbarItem = new ToolbarItem()
{
    Icon = "profileicon.png"
};
profilePicTollbarItem.Clicked += OnProfilePicClicked;
tabbedPage.ToolbarItems.Add(profilePicTollbarItem);

结果将如下所示:

enter image description here