gjf*_*nte 4 xaml xamarin.forms
我想将iOS上的标准Back按钮更改为NavigationBariOS中Cancel的"新建联系人"屏幕.
我在用Xamarin Forms.
编辑:
模态的XAML
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Xrm.Mca.Views.MyModalView">
<ContentPage.ToolbarItems>
<ToolbarItem x:Name="Cancel" Text="Cancel" ></ToolbarItem>
<ToolbarItem x:Name="Save" Text="Save" ></ToolbarItem>
</ContentPage.ToolbarItems>
<ContentPage.Content>
<TableView Intent="Form">
<TableRoot>
<TableSection Title="Details">
<EntryCell Label="Name" Placeholder="Entry your name" />
<EntryCell Label="Age" Placeholder="Entry your age" />
</TableSection>
</TableRoot>
</TableView>
</ContentPage.Content>
</ContentPage>
Run Code Online (Sandbox Code Playgroud)
在之前的屏幕中打开模态的代码隐藏
async Task OpenModal()
{
var page = new NavigationPage(new MyModalView ());
await App.Current.Navigation.PushModalAsync (page);
}
Run Code Online (Sandbox Code Playgroud)
完成您的请求的标准惯例是推送Modal并使用ToolBarItems.您可以在Xamarin论坛上找到将ToolBarItem应用于页面的示例.
如果你需要一个更具体的例子,请告诉我.
更新实例
这两个ToolbarItem就像这样:
var cancelItem = new ToolbarItem
{
Text = "Cancel"
};
var doneItem = new ToolbarItem
{
Text = "Done"
};
Run Code Online (Sandbox Code Playgroud)
现在您可以将这些添加到您的视图中:
this.ToolbarItems.Add(cancelItem);
this.ToolbarItems.Add(doneItem);
Run Code Online (Sandbox Code Playgroud)
你甚至可以绑定CommandProperty:
doneItem.SetBinding(MenuItem.CommandProperty, "DoneClicked");
Run Code Online (Sandbox Code Playgroud)
或者只需在用户点击项目时处理事件:
doneItem.Clicked += (object sender, System.EventArgs e) =>
{
// Perform action
};
Run Code Online (Sandbox Code Playgroud)
请记住将Modal包装在NavigationPage中,否则将不会出现ToolbarItem.
希望这可以帮助.
| 归档时间: |
|
| 查看次数: |
13053 次 |
| 最近记录: |