在Windows Phone中无法访问MessageBox类

3
我正在创建一个Windows Runtime应用程序,但似乎我无法访问MessageBox类。文档说明它位于System.Windows命名空间中,因此我添加了该命名空间,但仍无法访问MessageBox类。请参考下图: enter image description here
using System.Windows;
public sealed partial class BillPage : Page
{

    private Edge myEdge;
    public BillPage()
    {
        this.InitializeComponent();
        MessageBox.Show("Test", "Test");           
    }
}

你知道发生了什么吗?是我太蠢了还是怎么样?

文档:http://msdn.microsoft.com/en-us/library/windowsphone/develop/system.windows.messagebox(v=vs.105).aspx

完整代码:

using EdgeApp.Common;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.Graphics.Display;
using Windows.UI.ViewManagement;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using System.Windows;

// The Basic Page item template is documented at http://go.microsoft.com/fwlink/?LinkID=390556

namespace EdgeApp
{

    public sealed partial class BillPage : Page
    {
        private NavigationHelper navigationHelper;
        private ObservableDictionary defaultViewModel = new ObservableDictionary();
        private Edge myEdge;
        public BillPage()
        {
            this.InitializeComponent();
            myEdge = new Edge();
            this.navigationHelper = new NavigationHelper(this);
            this.navigationHelper.LoadState += this.NavigationHelper_LoadState;
            this.navigationHelper.SaveState += this.NavigationHelper_SaveState;

        }


        public NavigationHelper NavigationHelper
        {
            get { return this.navigationHelper; }
        }

        public ObservableDictionary DefaultViewModel
        {
            get { return this.defaultViewModel; }
        }


        private void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
        {
        }


        private void NavigationHelper_SaveState(object sender, SaveStateEventArgs e)
        {
        }

        #region NavigationHelper registration

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            this.navigationHelper.OnNavigatedTo(e);
        }

        protected override void OnNavigatedFrom(NavigationEventArgs e)
        {
            this.navigationHelper.OnNavigatedFrom(e);
        }

        #endregion

        private void MessageBoxTest(object sender, RoutedEventArgs e)
        {

            MessageBox.Show("text");

        }
    }
}

你所说的“没有访问MessageBox类”的意思是什么?是编译时错误还是运行时错误,还是根本无法工作等等? - RenniePet
“MessageBox”这个名称在当前上下文中不存在。我现在快疯了,这简直是最基本的东西。 - Levi Fuller
尝试添加 "using System.Windows.Forms;" - RenniePet
1
无法在Windows Store应用程序中使用Forms消息框。我尝试手动引用DLL,但当我尝试弹出它时,它崩溃了哈哈。 - Levi Fuller
1个回答

3

在Windows Runtime应用程序中,可以使用以下代码显示MessageBox:

new MessageDialog("Your Message Content").ShowAsync();

我的天啊,你真是个救星...如果他们能更新一下文档就好了。非常感谢你,Chris!你有没有想法为什么其他文档显示可以使用MessageBox类? - Levi Fuller
不用谢。也许他们的文档还没有完全更新。 - Chris Shao
即使在谷歌上搜索,也只会告诉你使用MessageBox... https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=How+to+show+message+on+Windows+Phone - Levi Fuller
3
可以在Windows Phone 8中使用MessageBox,但无法在Windows Phone 8.1(Runtime)中使用。 - Chris Shao

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接