MessageBox in windows 8 (Winrt) with dialog result
This is a much needed method to show a message box with a result;
Check this.
public static void ShowMessage(string message, Action<bool> executeMethod)
{
var dialog = new MessageDialog(message);
Action<IUICommand> handler = null;
handler = (result) =>
{
var isYes = false;
switch (result.Label)
{
case "Ok":
isYes = true;
break;
case "Cancel":
isYes = false;
break;
}
if (executeMethod != null)
{
executeMethod(isYes);
}
};
dialog.Commands.Add(new UICommand("Ok", new UICommandInvokedHandler(handler)));
dialog.Commands.Add(new UICommand("Cancel", new UICommandInvokedHandler(handler)));
dialog.DefaultCommandIndex = 1;
var showResult = dialog.ShowAsync();
}
Using this in a method.
ShowMessage("Are you sure ?", this.OnConfirmed);
private void OnConfirmed(bool isYes)
{
if (isYes)
{
// Do something
}
}
Using lambda expression (Untested code)
ShowMessage("Are you sure?", (isYes)=> {
if (isYes)
Using lambda expression (Untested code)
ShowMessage("Are you sure?", (isYes)=> {
if (isYes)
{
// Do something
} };)
Comments
Post a Comment