【问题标题】:No access to MessageBox class in Windows Phone无法访问 Windows Phone 中的 MessageBox 类
【发布时间】:2014-06-19 02:55:07
【问题描述】:

我正在创建一个Windows Runtime App,但我似乎无权访问MessageBox 类。文档说明它在 System.Windows 命名空间中,所以我添加了它,但我仍然无法访问 MessageBox 类。

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 类”到底是什么意思?编译时错误或运行时错误或它不起作用或...?
  • 当前上下文中不存在名称“MessageBox”。我现在快疯了。这就像有史以来最基本的事情。
  • 尝试添加“使用 System.Windows.Forms;”
  • 无法在 Windows 应用商店应用程序中使用表单消息框。我尝试手动引用 DLL,当我尝试弹出它时它崩溃了哈哈。

标签: c# windows-phone-8 windows-8


【解决方案1】:

在 Windows Runtime App 中,MessageBox 可以通过以下代码显示:

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

【讨论】:

  • 天哪,你真是个救世主……要是他们能更新他们的文档就好了。非常感谢你,克里斯!知道为什么其他文档显示您可以使用 MessageBox 类吗?
  • 不客气。也许他们的文档还没有完全更新。
  • 即使谷歌搜索也只会告诉你使用 MessageBox....google.com/…
  • 是的,MessageBox 可以在 Windows Phone 8 中使用。但不能在 Windows Phone 8.1(运行时)中使用
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-02-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多