【发布时间】:2014-11-10 03:38:53
【问题描述】:
我想在有人单击按钮时显示一个弹出窗口,该按钮位于从 web 服务加载的列表视图中,我如何向视图发送消息以调用 AlertDialog 函数?
我可能不太清楚,我将代码粘贴到下面看看我尝试了什么:
在我的视图模型中:
public void editPost(Post item)
{
PostToEdit = item;
// Call the popup function
}
在我看来:
public Dialog showEditPopup()
{
var customView = LayoutInflater.Inflate(Resource.Layout.EditDialog, null);
var builder = new AlertDialog.Builder(this);
builder.SetView(customView);
builder.SetPositiveButton("Save", SaveClicked);
builder.SetNegativeButton("Cancel", CancelClicked);
return builder.Create();
}
我尝试创建一个 onclick 函数来在视图中初始化我的 AlertDialog
var editButton = FindViewById<Button>(Resource.Id.editButton);
editButton.Click += delegate { ShowDialog(EditDialog); };
但应用程序崩溃,因为在 oncreate 时未加载帖子,因此 editButton 为 null 并且无法设置事件单击,所以我想在 viewmodel 中创建弹出窗口。
【问题讨论】:
-
您尝试过任何建议的方法吗?
-
是的,但最后在我的情况下使用 AlertDialog 并不是最好的方法,我必须在 Codebehind 和 ViewModel 之间以两种方式传递很多消息,所以我在查看并将参数绑定到VM。非常感谢您抽出宝贵的时间,您让我明白我的实施方式是错误的
标签: c# android xamarin mvvmcross android-alertdialog