Skip to content

Commit d1e94cd

Browse files
committed
Fix issue: Add the IsDefault property to MessageBox, set it to true, and press Enter to confirm (#221) 👍
1 parent 89c5b6f commit d1e94cd

3 files changed

Lines changed: 22 additions & 5 deletions

File tree

src/WPFDevelopers.Shared/Controls/MessageBox/MessageBox.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,39 @@ namespace WPFDevelopers.Controls
55
{
66
public static class MessageBox
77
{
8-
public static MessageBoxResult Show(string messageBoxText, Window owner = null, double buttonRadius = 0d)
8+
public static MessageBoxResult Show(string messageBoxText, Window owner = null, double buttonRadius = 0d, bool isDefault = true)
99
{
1010
var msg = new WDMessageBox(messageBoxText, buttonRadius);
11+
msg.IsDefault = isDefault;
1112
return GetWindow(msg, owner);
1213
}
1314

14-
public static MessageBoxResult Show(string messageBoxText, string caption, Window owner = null, double buttonRadius = 0d)
15+
public static MessageBoxResult Show(string messageBoxText, string caption, Window owner = null, double buttonRadius = 0d, bool isDefault = true)
1516
{
1617
var msg = new WDMessageBox(messageBoxText, caption, buttonRadius);
18+
msg.IsDefault = isDefault;
1719
return GetWindow(msg, owner);
1820
}
1921

20-
public static MessageBoxResult Show(string messageBoxText, string caption, MessageBoxButton button, Window owner = null, double buttonRadius = 0d)
22+
public static MessageBoxResult Show(string messageBoxText, string caption, MessageBoxButton button, Window owner = null, double buttonRadius = 0d, bool isDefault = true)
2123
{
2224
var msg = new WDMessageBox(messageBoxText, caption, button, buttonRadius);
25+
msg.IsDefault = isDefault;
2326
return GetWindow(msg, owner);
2427
}
2528

26-
public static MessageBoxResult Show(string messageBoxText, string caption, MessageBoxImage icon, Window owner = null, double buttonRadius = 0d)
29+
public static MessageBoxResult Show(string messageBoxText, string caption, MessageBoxImage icon, Window owner = null, double buttonRadius = 0d, bool isDefault = true)
2730
{
2831
var msg = new WDMessageBox(messageBoxText, caption, icon, buttonRadius);
32+
msg.IsDefault = isDefault;
2933
return GetWindow(msg, owner);
3034
}
3135

3236
public static MessageBoxResult Show(string messageBoxText, string caption, MessageBoxButton button,
33-
MessageBoxImage icon, Window owner = null, double buttonRadius = 0d)
37+
MessageBoxImage icon, Window owner = null, double buttonRadius = 0d, bool isDefault = true)
3438
{
3539
var msg = new WDMessageBox(messageBoxText, caption, button, icon, buttonRadius);
40+
msg.IsDefault = isDefault;
3641
return GetWindow(msg, owner);
3742
}
3843

src/WPFDevelopers.Shared/Controls/MessageBox/WDMessageBox.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,16 @@ public CornerRadius ButtonCornerRadius
5959
DependencyProperty.Register("ButtonCornerRadius", typeof(CornerRadius), typeof(WDMessageBox), new PropertyMetadata(null));
6060

6161

62+
public bool IsDefault
63+
{
64+
get { return (bool)GetValue(IsDefaultProperty); }
65+
set { SetValue(IsDefaultProperty, value); }
66+
}
67+
68+
public static readonly DependencyProperty IsDefaultProperty =
69+
DependencyProperty.Register("IsDefault", typeof(bool), typeof(WDMessageBox), new PropertyMetadata(true));
70+
71+
6272
static WDMessageBox()
6373
{
6474
DefaultStyleKeyProperty.OverrideMetadata(typeof(WDMessageBox),

src/WPFDevelopers.Shared/Styles/Styles.MessageBox.xaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
Width="60"
9494
helpers:ElementHelper.CornerRadius="{Binding Path=(controls:WDMessageBox.ButtonCornerRadius), RelativeSource={RelativeSource TemplatedParent}}"
9595
Content="{Binding [Yes], Source={x:Static resx:LanguageManager.Instance}}"
96+
IsDefault="{TemplateBinding IsDefault}"
9697
Style="{DynamicResource WD.PrimaryButton}"
9798
Visibility="Collapsed" />
9899
<Button
@@ -108,6 +109,7 @@
108109
Margin="6,0,0,0"
109110
helpers:ElementHelper.CornerRadius="{Binding Path=(controls:WDMessageBox.ButtonCornerRadius), RelativeSource={RelativeSource TemplatedParent}}"
110111
Content="{Binding [OK], Source={x:Static resx:LanguageManager.Instance}}"
112+
IsDefault="{TemplateBinding IsDefault}"
111113
Style="{DynamicResource WD.PrimaryButton}" />
112114
<Button
113115
x:Name="PART_ButtonCancel"

0 commit comments

Comments
 (0)