-
Notifications
You must be signed in to change notification settings - Fork 13
/
AdvancedMessageBoxHelper.cs
43 lines (37 loc) · 1.47 KB
/
AdvancedMessageBoxHelper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
namespace CnCNet.LauncherStub;
using System.Collections.ObjectModel;
public static class AdvancedMessageBoxHelper
{
public static int? ShowMessageBoxWithSelection(string message, string title, string[] selections)
{
var msgbox = new AdvancedMessageBox();
var model = (AdvancedMessageBoxViewModel)msgbox.DataContext;
model.Title = title;
model.Message = message;
var commands = new ObservableCollection<CommandViewModel>();
for (int i = 0; i < selections.Length; i++)
{
// passing just i to the lambda will not work as
// intended due to C# variable capture specifics
int iCaptured = i;
commands.Add(new CommandViewModel()
{
Text = selections[i],
Command = new RelayCommand(_ =>
{
msgbox.Result = iCaptured;
msgbox.Close();
}),
});
}
model.Commands = commands;
msgbox.ShowDialog();
return msgbox.Result as int?;
}
public static void ShowOkMessageBox(string message, string title, string okText = "OK") => ShowMessageBoxWithSelection(message, title, new[] { okText });
public static bool ShowYesNoMessageBox(string message, string title, string yesText = "Yes", string noText = "No")
{
int? result = ShowMessageBoxWithSelection(message, title, new[] { yesText, noText });
return result == 0;
}
}