変数 = new UICommand( テキスト);引数には、ダイアログに表示されるボタンのテキストを指定します。非常にシンプルですね。
《MessageDialog》.Commands.Add(《UICommand》);MessageDialogクラスには、Commandsというプロパティがあります。これは、UICommandをまとめて保管するコレクションが設定されたプロパティです。このコレクションにUICommandインスタンスを追加することで、そのIUICommandがボタンとして表示されるようになるのです。
UICommand 変数= await 《MessageDialog》.ShowAsync();ShowAsyncは、選択したボタンのUICommandを返すようになっています。ですので、こんな具合に返値を取り出せば、どのボタンを押したのかチェックすることができます。なお、返値はIUICommandというタイプになっていますが、これはUICommandのベースとなっているインターフェイスです。
※リストが表示されない場合
AddBlockなどの広告ブロックツールがONになっているとリストなどが表示されない場合があります。これらのツールをOFFにしてみてください。
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.InteropServices.WindowsRuntime; using System.Threading.Tasks; using Windows.Foundation; using Windows.Foundation.Collections; using Windows.UI.Popups; 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; namespace MyWin8App { public sealed partial class MainPage : Page { public MainPage() { this.InitializeComponent(); } private async void button1_click(object sender, RoutedEventArgs e) { string msg = "Hello, " + textbox1.Text + "!"; MessageDialog dlog = new MessageDialog(msg,"Hello"); UICommand cmd1 = new UICommand("最初の"); UICommand cmd2 = new UICommand("真ん中"); UICommand cmd3 = new UICommand("最後の"); dlog.Commands.Add(cmd1); dlog.Commands.Add(cmd2); dlog.Commands.Add(cmd3); IUICommand cmd = await dlog.ShowAsync(); textblock1.Text = cmd.Label + "を選んだね。"; } } }
<< 前へ | 次へ >> |