変数 = new UICommand( テキスト ,
《UICommandInvokedHandler》);
変数 = new UICommandInvokedHandler( メソッドの指定 );UICommandInvokedHandlerインスタンスは、引数にメソッドを指定してインスタンスを作成します。これで、そのメソッドを呼び出すためのインスタンスが作成されます。
UICommand cmd1 = new UICommand("OK", new引き数にはUICommandInvokedHandlerが用意されていますが、その引き数にはそれぞれmsgdlog_result_okとmsgdlog_result_noというメソッドが指定されています。では、これらのメソッドはどうなっているのでしょうか。
UICommandInvokedHandler(this.msgdlog_result_ok));
UICommand cmd2 = new UICommand("No...", new
UICommandInvokedHandler(this.msgdlog_result_no));
private void msgdlog_result_ok(IUICommand command){……}先ほどUICommandInvokedHandlerの引数に指定されていたものですね。これらのメソッドでは、引数にIUICommandが渡されています。これで、クリックしたボタンのUICommandが得られます。後は、それぞれのボタンに応じた処理をすればいい、というわけです。
private void msgdlog_result_no(IUICommand command){……}
※リストが表示されない場合
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("OK", new UICommandInvokedHandler(this.msgdlog_result_ok)); UICommand cmd2 = new UICommand("No...", new UICommandInvokedHandler(this.msgdlog_result_no)); dlog.Commands.Add(cmd1); dlog.Commands.Add(cmd2); await dlog.ShowAsync(); } private void msgdlog_result_ok(IUICommand command) { textblock1.Text = "OKしました。"; } private void msgdlog_result_no(IUICommand command) { textblock1.Text = "……何かご不満でも?"; } } }
<< 前へ | 次へ >> |