62

WP8.1 アプリでダウンロード エラーを表示するために MessageBox を使用したいと考えています。

追加した:

using System.Windows;

しかし、私が入力すると:

MessageBox.Show("");

エラーが発生します:

"The name 'MessageBox' does not exist in the current context"

オブジェクトブラウザで、そのようなクラスが存在する必要があることがわかり、「プロジェクト->参照の追加...->アセンブリ->フレームワーク」に、すべてのアセンブリが参照されていることが示されています。

私は何かが恋しいですか?または、メッセージボックスのようなものを表示する別の方法はありますか?

4

6 に答える 6

48

ZombieSheepの答えに追加したいだけです:また、カスタマイズは非常に簡単です

        var dialog = new MessageDialog("Are you sure?");
        dialog.Title = "Really?";
        dialog.Commands.Add(new UICommand { Label = "Ok", Id = 0 });
        dialog.Commands.Add(new UICommand { Label = "Cancel", Id = 1 });
        var res = await dialog.ShowAsync();

        if ((int)res.Id == 0)
        { *** }
于 2014-09-17T20:09:16.397 に答える
2

次のようなクラスを作成することもできます。コードの下に使用例があります。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.UI.Popups;

namespace someApp.ViewModels
{
    public static class Msgbox
    {
        static public async void Show(string mytext)
        {
            var dialog = new MessageDialog(mytext, "Testmessage");
            await dialog.ShowAsync();
        }
    }

}

クラスで使用する例

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace someApp.ViewModels
{
    public class MyClass{

        public void SomeMethod(){
            Msgbox.Show("Test");
        }

    } 
}
于 2017-04-23T10:13:45.873 に答える