c# - 关闭主窗口时如何使用 DisplayAlert
问题描述
我在 XAML 中有这个按钮:
<Button
x:Name="UpdateButton"
Padding="10"
Command="{Binding SaveAndUpdateCommand}"
HorizontalOptions="CenterAndExpand"
Text="Save and Update"
VerticalOptions="End" />
在后面的代码中,我设置了如下绑定命令:
SaveAndUpdateCommand = new Command(OnSaveAndUpdate, canExecute: () => { return IsDirty; });
系统运行,当对 GUI 进行更改时,按钮启用。然后在执行保存按钮禁用后。
但我想更进一步,当用户尝试用 X 关闭窗口(左上角)时使用if is DisplayAlert
。IsDirty
true
我的第一个想法是覆盖OnDisappearing
并制作它async
。它正确显示了弹出消息,但此后再也不会关闭窗口。我做了一些研究,很快发现从这个覆盖中显示弹出窗口是个坏主意。
我仍然不确定在 macOS 平台上的 Xamarin.Forms 应用程序中处理此问题的最简单方法是什么。总结一下:
User tries to close the main app window with X at top left
if IsDirty is true
Show alert (yes/no) and get response
if yes then save and continue closing
if no then just continue closing
理想情况下,它还会提供 Cancel 作为中止关闭的一种方式。
解决方案
推荐阅读
- java - 在我重新启动tomcat之前无法显示上传的图像
- javascript - NodeJS - multer - 根据请求属性更改文件名
- powershell - 如何使用 powershell 导出 PC 名称列表和该端点的特定组成员身份?
- python - ROS编程:试图让我的turtlebot在没有遇到障碍的情况下四处游荡
- c++ - MFC DestroyWindow 导致崩溃
- php - 如何在这个 html 输入字段中显示这个 php 脚本生成的文本?
- python-2.7 - Python Selenium:XPath 改变了我的变量的编码
- python - Python - 如何通过请求参数或其他方式发送值
- html - 单击 div 元素后如何以 HTML 格式上传图像
- java - 我所有的布局 xml 文件都变成了自动生成的文件