我是Xamarin的新手,我不知道如何在c#中执行以下操作.我想在单击Positive/Negative按钮时阻止alertdialog关闭.我需要先对输入进行一些验证.如果输入正确,则对话框可以关闭,否则我将显示带有说明的消息.基本上,我有以下代码:
private void CreateAddProjectDialog() {
//some code
var alert = new AlertDialog.Builder (this);
alert.SetTitle ("Create new project");
alert.SetView (layoutProperties);
alert.SetCancelable (false);
alert.SetPositiveButton("Create", HandlePositiveButtonClick);
alert.SetNegativeButton("Cancel", HandelNegativeButtonClick);
}
private void HandlePositiveButtonClick (object sender, EventArgs e) {
//Do some validation here and return false (prevent closing of dialog) if invalid, else close....
}
Run Code Online (Sandbox Code Playgroud)
现在,我在StackOverflow上重新发布以下文章:如何在单击按钮时阻止对话框关闭
我认为下面的代码(取自线程)有解决方案,但我不知道如何重写我的c#代码来实现Java:
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage("Test for preventing dialog close");
builder.setPositiveButton("Test",
new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
//Do nothing here because we …Run Code Online (Sandbox Code Playgroud)