有没有什么办法可以在没有用户交互的情况下关闭Xamarin.Forms DisplayAlert? 我可以提供的没有CancellationToken
。 那么我该如何取消它?关闭Xamarin.Forms DisplayAlert
2
A
回答
1
您不能使用默认的Xamarin警报。
看看ACR.UserDialogs NuGet包。它确实支持CancellationToken
s。或者如果您感觉勇敢的挖掘GitHub上的Xamarin.Forms回购并自己创建一个拉取请求!
0
我已创建自定义displayalert您可以使用任务回拨TaskCompletionSource如xamarin在我的方法建立DisplayAlert from it
public async Task<bool> ShowDialogAsync(string title, string message, string acceptMessage, string cancelMessage)
{
Grid ShowDialogMessage = null;
Grid CurrentPageGrid = (App.Instance.CurrentPage as ContentPage).Content as Grid;
TaskCompletionSource<bool> result = new TaskCompletionSource<bool>();
try
{
ShowDialogMessage = GenericView.CustomDisplayAlert(message, CurrentPageGrid.RowDefinitions.Count, CurrentPageGrid.ColumnDefinitions.Count,() =>
{
//here you can add your implementation
CurrentPageGrid.Children.Remove(ShowDialogMessage);
result.SetResult(true);
},
() =>
{
//here you can add your implementation
CurrentPageGrid.Children.Remove(ShowDialogMessage);
result.SetResult(false);
}, title, acceptMessage, cancelMessage);
CurrentPageGrid.Children.Add(ShowDialogMessage);
return await result.Task;
}
catch (Exception ex)
{
return await App.Current.MainPage.DisplayAlert(title, message, acceptMessage, cancelMessage);
#if DEBUG
throw ex;
#endif
}
}
我加入行动落实回调,,方法签名
public static Grid CustomDisplayAlert(string message, int rows, int columns, Action acceptAction, Action cancelAction, string title = "", string acceptMessage = "", string cancelMessage = "")
{ .....
相关问题
- 1. 订阅DisplayAlert在Xamarin.Forms
- 2. DisplayAlert导致应用程序崩溃在Xamarin.Forms
- 3. Spinner里面DisplayAlert(Xamarin.iOS)
- 4. 造型Xamarin.Foms DisplayAlert
- 5. Xamarin Forms DisplayAlert Button TextColor
- 6. Prism + Xamarin.Forms在Android上关闭应用后项目错误?
- 7. VBA DisplayAlert未设置为false
- 8. 如何在Xamarin.forms
- 9. 关闭/关闭WCSession
- 10. 的Http在Xamarin.Forms
- 11. Parent关闭时关闭Python
- 12. Tomcat关闭关闭jar
- 13. 关闭菜单/格关闭
- 14. 关闭Magpie缓存关闭
- 15. 关闭还是不关闭?
- 16. Xamarin.Forms(PCL)项目中的NotlmplementedException
- 17. DisplayAlert()不在自定义布局中显示
- 18. 关闭JS闭包
- 19. 关闭iOS电源按钮关闭应用程序关闭
- 20. 悬停时关闭模式窗口,关闭焦点时关闭
- 21. 关闭弹出窗口关闭直到浏览器关闭
- 22. Xamarin.Forms
- 23. 关闭
- 24. 关闭
- 25. 关闭
- 26. 在Android上设置Xamarin.forms崩溃MainPage - System.ArgumentException
- 27. 关于python关闭
- 28. 关闭/关闭屏幕的Android通知
- 29. Windows 2000关闭程序关闭
- 30. WPF MainWindow不能关闭。关闭