Mvvm Light对话框消息框。如何添加是,否而不是OK&取消?

时间:2014-02-11 01:46:41

标签: c# windows-phone-7 mvvm mvvm-light

我在我的wp7应用程序中使用mvvm light但我不确定如何超越简单的对话框。

我在我的视图后面的代码中有这个

 Messenger.Default.Register<DialogMessage>(
             this,
             msg =>
             {
                 var result = MessageBox.Show(
                     msg.Content,
                     msg.Caption,
                     msg.Button);

                 // Send callback
                 msg.ProcessCallback(result);
             });

我的ViewModel中有这样的东西

  var message = new DialogMessage("Select Yes or No!", null)
        {
            Button = MessageBoxButton.OK,
            Caption = "Yes or No"
        };

        Messenger.Default.Send(message);

那我怎么得到它所以它会是或否?

基本上我需要像MVVM那样的XNA对话框消息。

1 个答案:

答案 0 :(得分:0)

消息框与MVVM Light或MVVM模式无关。基本上,viewmodel通过Messenger发送消息进行查看,并在收到消息视图时通过显示标准的silverlight / windows phone消息框进行响应。因此我认为,您需要使用其他消息框(XNA或其他第三方库),因为Windows Phone API仅公开MessageBox类 [1] 的OK / Cancel版本。

这是我在网上找到的使用XNA消息框的众多示例之一。您可以通过添加对Microsoft.Xna.Framework和Microsoft.Xna的引用,在Silverlight版本的Windows Phone项目中使用它。 Framework.GamerServices:

来源:

http://dotnet.dzone.com/articles/delivering-message-using

代码:

Guide.BeginShowMessageBox("Version of Windows", "Pick a version of Windows.",
    new List<string> { "Vista", "Seven" }, 0, MessageBoxIcon.Error, 
    asyncResult => 
    {
        int? returned = Guide.EndShowMessageBox(asyncResult);
        Debug.WriteLine(returned.ToString());
    }, null);

MVVM版本:

Messenger.Default.Register<DialogMessage>(
     this,
     msg =>
         {
             Guide.BeginShowMessageBox("Version of Windows", "Pick a version of Windows.",
                   new List<string> {"Vista", "Seven"}, 0, MessageBoxIcon.Error,
                   asyncResult =>
                       {
                           int? returned = Guide.EndShowMessageBox(asyncResult);
                           Debug.WriteLine(returned.ToString());
                       }, null);
         });

结果:

enter image description here

相关问题