- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我有一个页面,点击工具栏上的加号按钮我调用了一个弹出页面
从弹出页面用户可以添加新条目或取消/关闭窗口而不做任何事情
一切正常,代码是这样的
public partial class SelectSchool : ContentPage
{
public SelectSchool()
{
InitializeComponent();
#region toolbar
ToolbarItem tbi = null;
if (Device.OS == TargetPlatform.Android)
{
tbi = new ToolbarItem("+", "plus", async () =>
{
var target_page = new AddSchool();
Navigation.PushModalAsync(target_page);
}, 0,0);
}
ToolbarItems.Add(tbi);
#endregion
this.Title = "Select School";
}
}
我的弹出页面是这样的
public partial class AddSchool : ContentPage
{
public AddSchool()
{
InitializeComponent();
}
private async void Button_OK_Clicked(object sender, EventArgs e)
{
//doing some operations like entry to db etc and close page
Navigation.PopModalAsync();
}
private void cancelClicked(object sender, EventArgs e)
{
Navigation.PopModalAsync();
}
}
但现在我想等待 Popup 关闭来做一些额外的编码,我尝试了下面的代码
if (Device.OS == TargetPlatform.Android)
{
tbi = new ToolbarItem("+", "plus", async () =>
{
var target_page = new AddSchool();
await Navigation.PushModalAsync(target_page);
//await till target_page is closed and once its closed call my next function here
}, 0,0);
}
但是 await 不起作用。我怎样才能在这个区域等待直到弹出窗口关闭?有什么想法吗??
最佳答案
在模态页面上使用 Disappearing
事件。
var modalPage = new ContentPage();
modalPage.Disappearing += (sender2, e2) =>
{
System.Diagnostics.Debug.WriteLine("The modal page is dismissed, do something now");
};
await content.Navigation.PushModalAsync(modalPage);
System.Diagnostics.Debug.WriteLine("The modal page is now on screen, hit back button");
EventWaitHandle
:var waitHandle = new EventWaitHandle(false, EventResetMode.AutoReset);
var modalPage = new ContentPage();
modalPage.Disappearing += (sender2, e2) =>
{
waitHandle.Set();
};
await content.Navigation.PushModalAsync(modalPage);
System.Diagnostics.Debug.WriteLine("The modal page is now on screen, hit back button");
await Task.Run(() => waitHandle.WaitOne());
System.Diagnostics.Debug.WriteLine("The modal page is dismissed, do something now");
关于c# - 等待 PushModalAsync 表单以 xamarin 表单关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39652909/
我有一个页面,点击工具栏上的加号按钮我调用了一个弹出页面 从弹出页面用户可以添加新条目或取消/关闭窗口而不做任何事情 一切正常,代码是这样的 public partial class Sele
问这个问题的原因我在 xamarin 表单 mvvm 架构中使用 PushAsync 时出错 await Navigation.PushAsync(new Page2()); 错误是 我已通过将 Pu
问这个问题的原因我在 xamarin 表单 mvvm 架构中使用 PushAsync 时出错 await Navigation.PushAsync(new Page2()); 错误是 我已通过将 Pu
Caliburn.Micro 3.0(和 Caliburn.Micro.Xamarin.Forms)是否实现了在 Xamarin.Forms 中模拟/支持 Navigation.PushModalAs
我正在开发不需要后退按钮的 Xamarin Forms 应用程序 (PCL)。该应用程序具有三个页面:一个用于加载数据的 SplashScreenPage,一个用于用户需要登录的 LoginPage
我是一名优秀的程序员,十分优秀!