Last active
August 29, 2015 14:12
-
-
Save igorkulman/fda1860b35d5312e9157 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Helper class for showing message dialogs | |
/// </summary> | |
public static class DialogHelper | |
{ | |
/// <summary> | |
/// Shows a dialog with given message and ok/cancel buttons. | |
/// </summary> | |
/// <param name="message">Message</param> | |
/// <param name="title">Title</param> | |
/// <param name="okText">OK text (optional)</param> | |
/// <param name="cancelText">Cancel text (optional)</param> | |
/// <returns>True if ok pressed, false otherwise</returns> | |
public static async Task<bool> ShowMessageDialog(string message, string title, string okText, string cancelText) | |
{ | |
bool result = false; | |
var dialog = new MessageDialog(message, title); | |
if (!string.IsNullOrWhiteSpace(okText)) | |
{ | |
dialog.Commands.Add(new UICommand(okText, cmd => result = true)); | |
} | |
if (!string.IsNullOrWhiteSpace(cancelText)) | |
{ | |
dialog.Commands.Add(new UICommand(cancelText, cmd => result = false)); | |
} | |
await dialog.ShowAsync(); | |
return result; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Helper class for showing message dialogs | |
/// </summary> | |
public class DialogHelperService | |
{ | |
/// <summary> | |
/// Shows a dialog with given message and ok/cancel buttons. | |
/// </summary> | |
/// <param name="message">Message</param> | |
/// <param name="title">Title</param> | |
/// <param name="okText">OK text (optional)</param> | |
/// <param name="cancelText">Cancel text (optional)</param> | |
/// <returns>True if ok pressed, false otherwise</returns> | |
public async Task<bool> ShowMessageDialog(string message, string title, string okText, string cancelText) | |
{ | |
bool result = false; | |
var dialog = new MessageDialog(message, title); | |
if (!string.IsNullOrWhiteSpace(okText)) | |
{ | |
dialog.Commands.Add(new UICommand(okText, cmd => result = true)); | |
} | |
if (!string.IsNullOrWhiteSpace(cancelText)) | |
{ | |
dialog.Commands.Add(new UICommand(cancelText, cmd => result = false)); | |
} | |
await dialog.ShowAsync(); | |
return result; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public async void Message() | |
{ | |
var res = await DialogHelper.ShowMessageDialog("Do you really want to do this?","My Title","Hell yeah!","No way"); | |
if (res) | |
{ | |
Result = "Hell yeah!"; | |
} else | |
{ | |
Result = "NOOOO!"; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Page.BottomAppBar> | |
<CommandBar> | |
<AppBarButton Icon="Accept" Label="go ask!" x:Name="Message" /> | |
</CommandBar> | |
</Page.BottomAppBar> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public async void Message() | |
{ | |
var res = await _dialogHelperService.ShowMessageDialog("Do you really want to do this?","My Title","Hell yeah!","No way"); | |
if (res) | |
{ | |
Result = "Hell yeah!"; | |
} else | |
{ | |
Result = "NOOOO!"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment