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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Animation;
namespace MediaBrowser.UI.Controls
{
/// <summary>
/// Interaction logic for ModalWindow.xaml
/// </summary>
public partial class ModalWindow : BaseModalWindow
{
public MessageBoxResult MessageBoxResult { get; set; }
public UIElement TextContent
{
set
{
pnlContent.Children.Clear();
var textBlock = value as TextBlock;
if (textBlock != null)
{
textBlock.SetResourceReference(TextBlock.StyleProperty, "ModalTextStyle");
}
pnlContent.Children.Add(value);
}
}
public string Text
{
set { TextContent = new TextBlock { Text = value }; }
}
private MessageBoxButton _button;
public MessageBoxButton Button
{
get { return _button; }
set
{
_button = value;
UpdateButtonVisibility();
OnPropertyChanged("Button");
}
}
private MessageBoxIcon _messageBoxImage;
public MessageBoxIcon MessageBoxImage
{
get { return _messageBoxImage; }
set
{
_messageBoxImage = value;
OnPropertyChanged("MessageBoxImage");
}
}
private string _caption;
public string Caption
{
get { return _caption; }
set
{
_caption = value;
txtCaption.Visibility = string.IsNullOrEmpty(value) ? Visibility.Collapsed : Visibility.Visible;
OnPropertyChanged("Caption");
}
}
public ModalWindow()
: base()
{
InitializeComponent();
}
protected override void OnInitialized(EventArgs e)
{
base.OnInitialized(e);
btnOk.Click += btnOk_Click;
btnCancel.Click += btnCancel_Click;
btnYes.Click += btnYes_Click;
btnNo.Click += btnNo_Click;
}
void btnNo_Click(object sender, RoutedEventArgs e)
{
MessageBoxResult = MessageBoxResult.No;
CloseModal();
}
void btnYes_Click(object sender, RoutedEventArgs e)
{
MessageBoxResult = MessageBoxResult.Yes;
CloseModal();
}
void btnCancel_Click(object sender, RoutedEventArgs e)
{
MessageBoxResult = MessageBoxResult.Cancel;
CloseModal();
}
void btnOk_Click(object sender, RoutedEventArgs e)
{
MessageBoxResult = MessageBoxResult.OK;
CloseModal();
}
private void UpdateButtonVisibility()
{
btnYes.Visibility = Button == MessageBoxButton.YesNo || Button == MessageBoxButton.YesNoCancel
? Visibility.Visible
: Visibility.Collapsed;
btnNo.Visibility = Button == MessageBoxButton.YesNo || Button == MessageBoxButton.YesNoCancel
? Visibility.Visible
: Visibility.Collapsed;
btnOk.Visibility = Button == MessageBoxButton.OK || Button == MessageBoxButton.OKCancel
? Visibility.Visible
: Visibility.Collapsed;
btnCancel.Visibility = Button == MessageBoxButton.OKCancel || Button == MessageBoxButton.YesNoCancel
? Visibility.Visible
: Visibility.Collapsed;
}
}
/// <summary>
/// I had to make my own enum that essentially clones MessageBoxImage
/// Some of the options share the same enum int value, and this was preventing databinding from working properly.
/// </summary>
public enum MessageBoxIcon
{
// Summary:
// No icon is displayed.
None,
//
// Summary:
// The message box contains a symbol consisting of white X in a circle with
// a red background.
Error,
//
// Summary:
// The message box contains a symbol consisting of a white X in a circle with
// a red background.
Hand,
//
// Summary:
// The message box contains a symbol consisting of white X in a circle with
// a red background.
Stop,
//
// Summary:
// The message box contains a symbol consisting of a question mark in a circle.
Question,
//
// Summary:
// The message box contains a symbol consisting of an exclamation point in a
// triangle with a yellow background.
Exclamation,
//
// Summary:
// The message box contains a symbol consisting of an exclamation point in a
// triangle with a yellow background.
Warning,
//
// Summary:
// The message box contains a symbol consisting of a lowercase letter i in a
// circle.
Information,
//
// Summary:
// The message box contains a symbol consisting of a lowercase letter i in a
// circle.
Asterisk
}
}
|