2017-01-23 73 views
2

我使用了具有兩個項目android和ios的xamarin.form(Portable)。Xamarin - 在操作欄添加標題和按鈕

我想補充的操作欄標題,將根據詳細信息頁面也希望在右側的操作欄中添加一個按鈕

我參考以下鏈接

https://github.com/xamarin/xamarin-forms-samples/tree/master/Navigation/MasterDetailPage

此鏈接更改幫助我創建導航頁面。但不能添加標題和按鈕在操作欄中

下面是我想要的操作欄的圖像。付款方式是可以根據詳細信息頁面,並在右側更改標題「+」是按鈕

enter image description here

請建議我我如何才能在操作欄中使用xamarin形式(Portable)的添加標題和按鈕

+0

您需要創建工具欄_saveAddToolBarIte m = new ToolbarItem() {Icon = Constants.ASSES_PLUS_ICON,}; _saveAddToolBarItem.Clicked + = _saveAddImage_Clicked; – sumeet

+0

我不想添加工具欄項。我改變了問題,添加圖像,讓你可以瞭解我想要的 –

+0

沒有任何其他選項,你需要使用工具欄添加加號圖標 – sumeet

回答

2

你需要一個像沒有任何其他選項,添加加號,而無需使用工具欄項目在主詳細頁面

繼創建頁面是一些示例代碼

public class TodoListPageCS : ContentPage 
{ 
    private ToolbarItem _saveAddToolBarItem; 

    public TodoListPageCS() 
    { 

     Title = "Page Name"; 
     _saveAddToolBarItem = new ToolbarItem() 
     { Text = "Save"}; 
     ToolbarItems.Add(_saveAddToolBarItem); 
     _saveAddToolBarItem.Clicked += _saveAddToolBarItem_Clicked; 
     Content = new StackLayout { 
      Children = { 
       new Label { 
        Text = "Todo list data goes here", 
        HorizontalOptions = LayoutOptions.Center, 
        VerticalOptions = LayoutOptions.CenterAndExpand 
       } 
      } 
     }; 
    } 

    private void _saveAddToolBarItem_Clicked(object sender, System.EventArgs e) 
    { 
     throw new System.NotImplementedException(); 
    } 
} 

否則,你需要創建自己的定製基頁,而不是內容頁

要改變工具欄的顏色參考以下鏈接: https://forums.xamarin.com/discussion/44586/navigationbar-background-image-renderer-android

enter image description here 跳這個代碼將有助於你

計算策略,以更改工具欄顏色:

Detail = new NavigationPage((Page)Activator.CreateInstance(item.TargetType)) { 
        BarBackgroundColor = Color.FromHex("#42a990"), 
        BarTextColor = Color.White, 
       }; 
+0

感謝它幫助我很多。你能否告訴我如何將標題對齊? –