-
Notifications
You must be signed in to change notification settings - Fork 258
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1.Add shadow effect to messagebox 2.If no window has focus, add a border to the pop-up messagebox control 3.Add draggable Messagebox 4.Add the input parameter owner to specify the parent form
- Loading branch information
1 parent
f39fa88
commit ede0dbd
Showing
4 changed files
with
62 additions
and
37 deletions.
There are no files selected for viewing
This file contains 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
50 changes: 25 additions & 25 deletions
50
src/WPFDevelopers.Shared/Controls/MessageBox/MessageBox.cs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,71 @@ | ||
using System.Linq; | ||
using System.Security.Cryptography; | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
using System.Windows.Documents; | ||
using System.Windows.Media; | ||
using System.Windows.Media.Media3D; | ||
using System.Windows.Shapes; | ||
using WPFDevelopers.Helpers; | ||
using WPFDevelopers.Utilities; | ||
|
||
namespace WPFDevelopers.Controls | ||
{ | ||
public static class MessageBox | ||
{ | ||
public static MessageBoxResult Show(string messageBoxText) | ||
public static MessageBoxResult Show(string messageBoxText,Window owner = null) | ||
{ | ||
var msg = new WPFMessageBox(messageBoxText); | ||
return GetWindow(msg); | ||
return GetWindow(msg, owner); | ||
} | ||
|
||
public static MessageBoxResult Show(string messageBoxText, string caption) | ||
public static MessageBoxResult Show(string messageBoxText, string caption, Window owner = null) | ||
{ | ||
var msg = new WPFMessageBox(messageBoxText, caption); | ||
return GetWindow(msg); | ||
return GetWindow(msg, owner); | ||
} | ||
|
||
public static MessageBoxResult Show(string messageBoxText, string caption, MessageBoxButton button) | ||
public static MessageBoxResult Show(string messageBoxText, string caption, MessageBoxButton button, Window owner = null) | ||
{ | ||
var msg = new WPFMessageBox(messageBoxText, caption, button); | ||
return GetWindow(msg); | ||
return GetWindow(msg, owner); | ||
} | ||
|
||
public static MessageBoxResult Show(string messageBoxText, string caption, MessageBoxImage icon) | ||
public static MessageBoxResult Show(string messageBoxText, string caption, MessageBoxImage icon, Window owner = null) | ||
{ | ||
var msg = new WPFMessageBox(messageBoxText, caption, icon); | ||
return GetWindow(msg); | ||
return GetWindow(msg, owner); | ||
} | ||
|
||
public static MessageBoxResult Show(string messageBoxText, string caption, MessageBoxButton button, | ||
MessageBoxImage icon) | ||
MessageBoxImage icon, Window owner = null) | ||
{ | ||
var msg = new WPFMessageBox(messageBoxText, caption, button, icon); | ||
return GetWindow(msg); | ||
return GetWindow(msg, owner); | ||
} | ||
|
||
private static MessageBoxResult GetWindow(WPFMessageBox msg) | ||
private static MessageBoxResult GetWindow(WPFMessageBox msg, Window owner = null) | ||
{ | ||
try | ||
msg.WindowStartupLocation = WindowStartupLocation.CenterOwner; | ||
if (owner != null) | ||
{ | ||
msg.CreateMask(); | ||
msg.Owner = owner; | ||
msg.ShowDialog(); | ||
} | ||
else | ||
{ | ||
msg.WindowStartupLocation = WindowStartupLocation.CenterOwner; | ||
Window win = null; | ||
if (Application.Current.Windows.Count > 0) | ||
win = Application.Current.Windows.OfType<Window>().FirstOrDefault(o => o.IsActive); | ||
if (win != null) | ||
{ | ||
if (win.WindowState == WindowState.Minimized) | ||
msg.BorderThickness = new Thickness(1); | ||
msg.CreateMask(); | ||
msg.Owner = win; | ||
msg.ShowDialog(); | ||
} | ||
else | ||
{ | ||
msg.BorderThickness = new Thickness(1); | ||
msg.Show(); | ||
return msg.Result; | ||
} | ||
catch (System.Exception) | ||
{ | ||
throw; | ||
} | ||
} | ||
return msg.Result; | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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