2017-02-13 153 views
0

我想在导航栏中这样的中间增加一个标志:在导航栏中间添加徽标?

<ContentPage.ToolbarItems> 
    <ToolbarItem Icon="logo.png" Activated="RefButtonClicked"></ToolbarItem> 
</ContentPage.ToolbarItems> 

我也试过这样:

var cancelItem = new ToolbarItem 
{ 
    Text = "Cancel", 
    Icon = "tabalilogo.png", 
    Order = ToolbarItemOrder.Secondary 
}; 

一切我试图定位在导航的右侧的标志酒吧。我该如何居中呢?

+0

我认为你的问题为android。它似乎不可能,除非你禁用工具栏并创建你自定义的。我有类似的要求,我最终做自定义工具栏 – batmaci

+0

@ batmaci你可以给我的指示或参考,因为我从来没有做过自定义渲染? –

+1

我不是指自定义渲染器,而是自定义工具栏。我给你作为答案。 – batmaci

回答

1

我不确定这是否可以使用现有的工具栏实现,但我有类似的要求,我不知道如何实现在导航页面上使用Xamarin表单工具栏。因此我决定使用模态页面,并在后面的代码中禁用导航页面,并使用下面的代码行。

NavigationPage.SetHasNavigationBar(this, false); 

我使用XAML和我创建了absolutelayout自定义导航如下

<AbsoluteLayout x:Name="slToolbar" Grid.Row="0" > 
     <Button x:Name="Cancel" BackgroundColor="#ADD8E6" Image="cancel.png" Command="{Binding CancelClick}" AbsoluteLayout.LayoutFlags="PositionProportional"> 
      <AbsoluteLayout.LayoutBounds> 
      <OnPlatform x:TypeArguments="Rectangle" iOS="0, .5, 36, 36" Android="0, .5, 36, 36" WinPhone="0, .5, 50, 50" /> 
      </AbsoluteLayout.LayoutBounds> 
     </Button> 


     <StackLayout Orientation="Horizontal" AbsoluteLayout.LayoutFlags="PositionProportional"> 
      <AbsoluteLayout.LayoutBounds> 
      <OnPlatform x:TypeArguments="Rectangle" iOS="1,.5,110,50" Android="1,.5,50,36" WinPhone="1,.5,110,50" /> 
      </AbsoluteLayout.LayoutBounds> 


      <ContentView > 
      <OnPlatform x:TypeArguments="View"> 
       <OnPlatform.iOS> 
       <Button x:Name="NewIOS" BackgroundColor="#ADD8E6" Image="ic_add.png" Command="{Binding AddNew}" ></Button> 
       </OnPlatform.iOS> 
       <OnPlatform.WinPhone> 
       <Button x:Name="NewWP" BackgroundColor="#ADD8E6" Command="{Binding AddNew}" Image="ic_add.png"/> 
       </OnPlatform.WinPhone> 
      </OnPlatform> 
      </ContentView> 


      <Button x:Name="btnSave" BackgroundColor="#ADD8E6" Image="check.png" Command="{Binding SaveClick}" HorizontalOptions="End" ></Button> 
     </StackLayout> 
     </AbsoluteLayout> 

这个代码将产生类似下面。我有角落里的图标,但它们肯定可以放在任何地方。我用取消图标而不是后退按钮。当然,在这种情况下,你需要处理后退按钮(取消按钮)点击你自己。下面的截图是从UWP应用程序,但在Android和IOS我得到类似的结果。

enter image description here

+0

我想出了你的意思,我会试试这个 –

+1

你是否期待这将与tabbedpage一起工作? –

+0

@AhmedSayed Onn我的android项目,我更喜欢使用侧边菜单,但在UWP上我使用标签页,它对我来说看起来很好。我不认为这与XF默认工具栏有什么不同。设想一下左边的X按钮,而不是箭头。 – batmaci