3
3
using iNKORE . UI . WPF . Modern . Extensions ;
4
4
using System ;
5
5
using System . Linq ;
6
+ using System . Media ;
6
7
using System . Threading . Tasks ;
7
8
using System . Windows ;
8
9
@@ -203,7 +204,7 @@ public static MessageBoxResult Show(Window owner, string messageBoxText, string
203
204
/// <returns>A <see cref="MessageBoxResult"/> value that specifies which message box button is clicked by the user.</returns>
204
205
/// <remarks>By default, the message box appears in front of the window that is currently active.</remarks>
205
206
public static MessageBoxResult Show ( Window owner , string messageBoxText , string caption , MessageBoxButton button , MessageBoxImage icon , MessageBoxResult ? defaultResult ) =>
206
- Show ( owner , messageBoxText , caption , button , icon . ToSymbol ( ) , defaultResult ) ;
207
+ Show ( owner , messageBoxText , caption , button , icon . ToSymbol ( ) , defaultResult , icon . ToAlertSound ( ) ) ;
207
208
208
209
/// <summary>
209
210
/// Displays a message box in front of the specified window. The message box displays a message, title bar caption, button, and icon; and accepts a default message box result and returns a result.
@@ -216,8 +217,8 @@ public static MessageBoxResult Show(Window owner, string messageBoxText, string
216
217
/// <param name="defaultResult">A <see cref="MessageBoxResult"/> value that specifies the default result of the message box.</param>
217
218
/// <returns>A <see cref="MessageBoxResult"/> value that specifies which message box button is clicked by the user.</returns>
218
219
/// <remarks>By default, the message box appears in front of the window that is currently active.</remarks>
219
- public static MessageBoxResult Show ( Window owner , string messageBoxText , string caption , MessageBoxButton button , string icon , MessageBoxResult ? defaultResult ) =>
220
- Show ( owner , messageBoxText , caption , button , new FontIconSource { Glyph = icon , FontSize = 30 } , defaultResult ) ;
220
+ public static MessageBoxResult Show ( Window owner , string messageBoxText , string caption , MessageBoxButton button , string icon , MessageBoxResult ? defaultResult , SystemSound sound = null ) =>
221
+ Show ( owner , messageBoxText , caption , button , new FontIconSource { Glyph = icon , FontSize = 30 } , defaultResult , sound ) ;
221
222
222
223
/// <summary>
223
224
/// Displays a message box in front of the specified window. The message box displays a message, title bar caption, button, and icon; and accepts a default message box result and returns a result.
@@ -230,7 +231,7 @@ public static MessageBoxResult Show(Window owner, string messageBoxText, string
230
231
/// <param name="defaultResult">A <see cref="MessageBoxResult"/> value that specifies the default result of the message box.</param>
231
232
/// <returns>A <see cref="MessageBoxResult"/> value that specifies which message box button is clicked by the user.</returns>
232
233
/// <remarks>By default, the message box appears in front of the window that is currently active.</remarks>
233
- public static MessageBoxResult Show ( Window owner , string messageBoxText , string caption , MessageBoxButton button , IconSource icon , MessageBoxResult ? defaultResult )
234
+ public static MessageBoxResult Show ( Window owner , string messageBoxText , string caption , MessageBoxButton button , IconSource icon , MessageBoxResult ? defaultResult , SystemSound ? sound = null )
234
235
{
235
236
if ( owner is null )
236
237
{
@@ -248,6 +249,11 @@ public static MessageBoxResult Show(Window owner, string messageBoxText, string
248
249
WindowStartupLocation = owner is null ? WindowStartupLocation . CenterScreen : WindowStartupLocation . CenterOwner
249
250
} ;
250
251
252
+ if ( MakeSound )
253
+ {
254
+ window . SystemSoundOnLoaded = sound ;
255
+ }
256
+
251
257
return window . ShowDialog ( ) ;
252
258
}
253
259
@@ -447,7 +453,7 @@ public static Task<MessageBoxResult> ShowAsync(Window owner, string messageBoxTe
447
453
/// <returns>An asynchronous operation showing the message box. When complete, returns a <see cref="MessageBoxResult"/>.</returns>
448
454
/// <remarks>By default, the message box appears in front of the window that is currently active.</remarks>
449
455
public static Task < MessageBoxResult > ShowAsync ( Window owner , string messageBoxText , string caption , MessageBoxButton button , MessageBoxImage icon , MessageBoxResult ? defaultResult ) =>
450
- ShowAsync ( owner , messageBoxText , caption , button , icon . ToSymbol ( ) , defaultResult ) ;
456
+ ShowAsync ( owner , messageBoxText , caption , button , icon . ToSymbol ( ) , defaultResult , icon . ToAlertSound ( ) ) ;
451
457
452
458
/// <summary>
453
459
/// Begins an asynchronous operation to displays a message box in front of the specified window. The message box displays a message, title bar caption, button, and icon; and accepts a default message box result and returns a result.
@@ -460,8 +466,8 @@ public static Task<MessageBoxResult> ShowAsync(Window owner, string messageBoxTe
460
466
/// <param name="defaultResult">A <see cref="MessageBoxResult"/> value that specifies the default result of the message box.</param>
461
467
/// <returns>An asynchronous operation showing the message box. When complete, returns a <see cref="MessageBoxResult"/>.</returns>
462
468
/// <remarks>By default, the message box appears in front of the window that is currently active.</remarks>
463
- public static Task < MessageBoxResult > ShowAsync ( Window owner , string messageBoxText , string caption , MessageBoxButton button , string icon , MessageBoxResult ? defaultResult ) =>
464
- ShowAsync ( owner , messageBoxText , caption , button , new FontIconSource { Glyph = icon , FontSize = 30 } , defaultResult ) ;
469
+ public static Task < MessageBoxResult > ShowAsync ( Window owner , string messageBoxText , string caption , MessageBoxButton button , string icon , MessageBoxResult ? defaultResult , SystemSound sound = null ) =>
470
+ ShowAsync ( owner , messageBoxText , caption , button , new FontIconSource { Glyph = icon , FontSize = 30 } , defaultResult , sound ) ;
465
471
466
472
/// <summary>
467
473
/// Begins an asynchronous operation to displays a message box in front of the specified window. The message box displays a message, title bar caption, button, and icon; and accepts a default message box result and returns a result.
@@ -474,7 +480,7 @@ public static Task<MessageBoxResult> ShowAsync(Window owner, string messageBoxTe
474
480
/// <param name="defaultResult">A <see cref="MessageBoxResult"/> value that specifies the default result of the message box.</param>
475
481
/// <returns>An asynchronous operation showing the message box. When complete, returns a <see cref="MessageBoxResult"/>.</returns>
476
482
/// <remarks>By default, the message box appears in front of the window that is currently active.</remarks>
477
- public static Task < MessageBoxResult > ShowAsync ( Window owner , string messageBoxText , string caption , MessageBoxButton button , IconSource icon , MessageBoxResult ? defaultResult )
483
+ public static Task < MessageBoxResult > ShowAsync ( Window owner , string messageBoxText , string caption , MessageBoxButton button , IconSource icon , MessageBoxResult ? defaultResult , SystemSound sound = null )
478
484
{
479
485
TaskCompletionSource < MessageBoxResult > taskSource = new TaskCompletionSource < MessageBoxResult > (
480
486
#if ! NET452
@@ -484,7 +490,7 @@ public static Task<MessageBoxResult> ShowAsync(Window owner, string messageBoxTe
484
490
485
491
Application . Current . Dispatcher . Invoke ( ( ) =>
486
492
{
487
- MessageBoxResult result = Show ( owner , messageBoxText , caption , button , icon , defaultResult ) ;
493
+ MessageBoxResult result = Show ( owner , messageBoxText , caption , button , icon , defaultResult , sound ) ;
488
494
taskSource . TrySetResult ( result ) ;
489
495
} ) ;
490
496
0 commit comments