-
Notifications
You must be signed in to change notification settings - Fork 136
Expand file tree
/
Copy pathMsgBoxWrapper.cs
More file actions
83 lines (75 loc) · 2.16 KB
/
Copy pathMsgBoxWrapper.cs
File metadata and controls
83 lines (75 loc) · 2.16 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using PCL.Core.App.Localization;
namespace PCL.Core.UI;
[Obsolete("Use PCL.Core.UI.Dialog instead")]
public record MsgBoxButtonInfo(
string Context,
int Value = 0,
Action? OnClick = null
);
[Obsolete("Use PCL.Core.UI.DialogTheme instead")]
public enum MsgBoxTheme
{
Info,
Warning,
Error
}
public delegate void MsgBoxHandler(
string message,
string caption,
ICollection<MsgBoxButtonInfo> buttons,
MsgBoxTheme theme,
bool block,
ref int result
);
[Obsolete("Use PCL.Core.UI.Dialog instead")]
public static class MsgBoxWrapper
{
public static event MsgBoxHandler? OnShow;
public static int ShowWithCustomButtons(
string message,
string caption,
MsgBoxTheme theme,
bool block,
ICollection<MsgBoxButtonInfo> buttonCollection)
{
var buttons = new Collection<DialogButton>();
foreach (var btn in buttonCollection)
{
buttons.Add(new DialogButton(btn.Context, btn.OnClick));
}
var result = Dialog.Show(new DialogContext
{
Caption = message,
Title = caption,
Theme = (DialogTheme)(int)theme,
Block = block,
Content = null,
Buttons = buttons,
});
return result;
}
public static int ShowWithCustomButtons(
string message,
string? caption = null,
MsgBoxTheme theme = MsgBoxTheme.Info,
bool block = true,
params MsgBoxButtonInfo[] buttons)
{
return ShowWithCustomButtons(message, caption ?? Lang.Text("Common.Dialog.Title"), theme, block, buttonCollection: buttons);
}
public static int Show(
string message,
string? caption = null,
MsgBoxTheme theme = MsgBoxTheme.Info,
bool block = true,
params string[] buttons)
{
var index = 0;
var list = buttons.Select(button => new MsgBoxButtonInfo(button, ++index)).ToList();
return ShowWithCustomButtons(message, caption ?? Lang.Text("Common.Dialog.Title"), theme, block, list);
}
}