【问题标题】:Capture Alert Dialog Button Event捕获警报对话框按钮事件
【发布时间】:2016-05-16 15:46:36
【问题描述】:

我添加了 Acr.UserDialogs 插件并调用如下,我可以看到带有OK 按钮的简单警报。到目前为止一切顺利,但我想知道如何捕获OK 按钮点击事件?

public void Save()
{
  if (!isExit)
  {
     OnExit(this, null);
  }
  else
  {
     IsValid = false;
     Mvx.Resolve<IUserDialogs>().Alert("it is not valid");
  }
}

【问题讨论】:

    标签: c# xamarin mvvmcross


    【解决方案1】:

    只需传递一个AlertConfig 并设置OnOk 操作。

    var alertConfig = new AlertConfig {
        Message = "it is not valid",
        OkText = "Okely",
        OnOk = () => { Debug.WriteLine("ok pressed"); }
    };
    
    Mvx.Resolve<IUserDialogs>().Alert(alertConfig);
    

    7.0+ 版更新:

    OnOk 已重命名为 OnAction 参见:https://github.com/aritchie/userdialogs/blob/master/src/Acr.UserDialogs/AlertConfig.cs#L16

    var alertConfig = new AlertConfig {
        Message = "it is not valid",
        OkText = "Okely",
        OnAction = () => { Debug.WriteLine("ok pressed"); }
    };
    
    Mvx.Resolve<IUserDialogs>().Alert(alertConfig);
    

    【讨论】:

    • 我尝试使用 OnOk,但它给了我一个错误。你能帮忙吗?
    • 我正在使用 Acr.UserDialogs v7.0.1 和@NickKing 有同样的问题。有没有人找到新版本的正确答案?目前我正在使用没有取消按钮文本的 ConfirmDialog,但这很难看
    【解决方案2】:

    在 Arc.UserDialogs 7.0.1 中,您需要按以下方式进行操作:

    var alertConfig = new AlertConfig
    {
        Message = message,
        OkText = "AppSyncViewModel_Alert_Retry".Translate(),
        OnAction = YourAction
    };
    Mvx.IoCProvider.Resolve<IUserDialogs>().Alert(alertConfig);
    

    【讨论】:

      猜你喜欢
      • 2012-01-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-20
      • 2015-08-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多