>我在单击按钮时显示一个ModalView(导航页面(。 它运作良好。我想关闭"后退"按钮上的模态视图。 如果你有任何想法指导我。
我的代码如下。 按钮单击事件
protected void btnEdit_Click(object sender, EventArgs e)
{
var navigation = new NavigationPage(new Settings());
UIViewController navc = navigation.CreateViewController();
navc.ModalPresentationStyle = UIModalPresentationStyle.FullScreen;
this.PresentViewController(navc, true, null);
}
设置表单代码
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class Settings : ContentPage
{
public Settings()
{
var backItem = new ToolbarItem
{
Text = "Back"
};
this.ToolbarItems.Add(backItem);
backItem .SetBinding(MenuItem.CommandProperty, "BackClicked");
backItem .Clicked += (object sender, System.EventArgs e) =>
{
**// This code Not working**
Navigation.PopModalAsync(false);
};
InitializeComponent();
}
}
正如@Jason评论中提到的,您似乎正在将本机iOS代码与Xamarin.Forms代码混合在一起。若要从 XamForms 打开模式视图,可以调用Navigation.PushModal()
:
protected async void btnEdit_Click(object sender, EventArgs e)
{
var navigation = new NavigationPage(new Settings());
await Navigation.PushModalAsync(navigation);
}
根据评论进行更新
public class MyTabbarPage : TabbarPage
{
...
public void ButtonClicked()
{
var navigation = new NavigationPage(new Settings());
await Navigation.PushModalAsync(navigation);
}
}
// Inside renderer
protected async void btnEdit_Click(object sender, EventArgs e)
{
(Element as MyTabbarPage).ButtonClicked();
}
我按照下面的代码调用XamForms类函数及其工作。
protected void btnEdit_Click(object sender, EventArgs e)
{
Maintabpage obj =(Maintabpage)Xamarin.Forms.Application.Current.MainPage;
obj.ButtonClicked();
}