diff --git a/demo/Ursa.Demo/Pages/MessageBoxDemo.axaml b/demo/Ursa.Demo/Pages/MessageBoxDemo.axaml
index e9f6213..a2ed0b1 100644
--- a/demo/Ursa.Demo/Pages/MessageBoxDemo.axaml
+++ b/demo/Ursa.Demo/Pages/MessageBoxDemo.axaml
@@ -9,5 +9,9 @@
x:Class="Ursa.Demo.Pages.MessageBoxDemo">
+
+
+
+
diff --git a/demo/Ursa.Demo/ViewModels/MessageBoxDemoViewModel.cs b/demo/Ursa.Demo/ViewModels/MessageBoxDemoViewModel.cs
index 3d95040..4afcb64 100644
--- a/demo/Ursa.Demo/ViewModels/MessageBoxDemoViewModel.cs
+++ b/demo/Ursa.Demo/ViewModels/MessageBoxDemoViewModel.cs
@@ -9,14 +9,42 @@ namespace Ursa.Demo.ViewModels;
public class MessageBoxDemoViewModel: ObservableObject
{
public ICommand DefaultMessageBoxCommand { get; set; }
+ public ICommand OkCommand { get; set; }
+ public ICommand YesNoCommand { get; set; }
+ public ICommand YesNoCancelCommand { get; set; }
+ public ICommand OkCancelCommand { get; set; }
public MessageBoxDemoViewModel()
{
DefaultMessageBoxCommand = new AsyncRelayCommand(OnDefaultMessageAsync);
+ OkCommand = new AsyncRelayCommand(OnOkAsync);
+ YesNoCommand = new AsyncRelayCommand(OnYesNoAsync);
+ YesNoCancelCommand = new AsyncRelayCommand(OnYesNoCancelAsync);
+ OkCancelCommand = new AsyncRelayCommand(OnOkCancelAsync);
}
private async Task OnDefaultMessageAsync()
{
var result = await MessageBox.ShowAsync("Hello Message Box");
}
+
+ private async Task OnOkAsync()
+ {
+ var result = await MessageBox.ShowAsync("Hello Message Box", "Hello", MessageBoxButton.OK);
+ }
+
+ private async Task OnYesNoAsync()
+ {
+ var result = await MessageBox.ShowAsync("Hello Message Box", "Hello", MessageBoxButton.YesNo);
+ }
+
+ private async Task OnYesNoCancelAsync()
+ {
+ var result = await MessageBox.ShowAsync("Hello Message Box", "Hello", MessageBoxButton.YesNoCancel);
+ }
+
+ private async Task OnOkCancelAsync()
+ {
+ var result = await MessageBox.ShowAsync("Hello Message Box", "Hello", MessageBoxButton.OKCancel);
+ }
}
\ No newline at end of file
diff --git a/src/Ursa.Themes.Semi/Controls/MessageBoxWindow.axaml b/src/Ursa.Themes.Semi/Controls/MessageBoxWindow.axaml
index a2c496f..b10410b 100644
--- a/src/Ursa.Themes.Semi/Controls/MessageBoxWindow.axaml
+++ b/src/Ursa.Themes.Semi/Controls/MessageBoxWindow.axaml
@@ -4,7 +4,7 @@
xmlns:u="https://irihi.tech/ursa">
-
+
@@ -24,13 +24,30 @@
-
-
+
+
+
+ Grid.Column="1"
+ Margin="0,4,4,0"
+ Background="{DynamicResource CaptionButtonClosePointeroverBackground}"
+ BorderBrush="{DynamicResource CaptionButtonClosePressedBackground}"
+ Theme="{DynamicResource CaptionButton}">
+
+
+
+
+
+
-
-
-
-
-
+
+
+
+
+
diff --git a/src/Ursa/Controls/MessageBox/MessageBox.cs b/src/Ursa/Controls/MessageBox/MessageBox.cs
index 9fa9c02..1822d79 100644
--- a/src/Ursa/Controls/MessageBox/MessageBox.cs
+++ b/src/Ursa/Controls/MessageBox/MessageBox.cs
@@ -31,4 +31,32 @@ public static class MessageBox
return MessageBoxResult.None;
}
}
+
+ public static async Task ShowAsync(string message, string title, MessageBoxButton button)
+ {
+ var messageWindow = new MessageBoxWindow(button)
+ {
+ Content = message,
+ Title = title
+ };
+ var lifetime = Application.Current?.ApplicationLifetime;
+ if (lifetime is IClassicDesktopStyleApplicationLifetime classLifetime)
+ {
+ var main = classLifetime.MainWindow;
+ if (main is null)
+ {
+ messageWindow.Show();
+ return MessageBoxResult.None;
+ }
+ else
+ {
+ var result = await messageWindow.ShowDialog(main);
+ return result;
+ }
+ }
+ else
+ {
+ return MessageBoxResult.None;
+ }
+ }
}
\ No newline at end of file
diff --git a/src/Ursa/Controls/MessageBox/MessageBoxWindow.cs b/src/Ursa/Controls/MessageBox/MessageBoxWindow.cs
index 2e111ae..259bf05 100644
--- a/src/Ursa/Controls/MessageBox/MessageBoxWindow.cs
+++ b/src/Ursa/Controls/MessageBox/MessageBoxWindow.cs
@@ -93,39 +93,80 @@ public class MessageBoxWindow: Window
{
_cancelButton.Click += OnCancelButtonClick;
}
+ SetButtonVisibility();
+ }
+
+ private void SetButtonVisibility()
+ {
+ if (_buttonConfigs == MessageBoxButton.OK)
+ {
+ if (_closeButton != null) _closeButton.IsVisible = true;
+ if (_yesButton != null) _yesButton.IsVisible = false;
+ if (_noButton != null) _noButton.IsVisible = false;
+ if (_okButton != null) _okButton.IsVisible = true;
+ if (_cancelButton != null) _cancelButton.IsVisible = false;
+ }
+ else if (_buttonConfigs == MessageBoxButton.OKCancel)
+ {
+ if (_closeButton != null) _closeButton.IsVisible = true;
+ if (_yesButton != null) _yesButton.IsVisible = false;
+ if (_noButton != null) _noButton.IsVisible = false;
+ if (_okButton != null) _okButton.IsVisible = true;
+ if (_cancelButton != null) _cancelButton.IsVisible = true;
+ }
+ else if (_buttonConfigs == MessageBoxButton.YesNo)
+ {
+ if (_closeButton != null) _closeButton.IsVisible = false;
+ if (_yesButton != null) _yesButton.IsVisible = true;
+ if (_noButton != null) _noButton.IsVisible = true;
+ if (_okButton != null) _okButton.IsVisible = false;
+ if (_cancelButton != null) _cancelButton.IsVisible = false;
+ }
+ else if (_buttonConfigs == MessageBoxButton.YesNoCancel)
+ {
+ if (_closeButton != null) _closeButton.IsVisible = true;
+ if (_yesButton != null) _yesButton.IsVisible = true;
+ if (_noButton != null) _noButton.IsVisible = true;
+ if (_okButton != null) _okButton.IsVisible = false;
+ if (_cancelButton != null) _cancelButton.IsVisible = true;
+ }
}
private void OnCloseButtonClick(object sender, RoutedEventArgs e)
{
- this.Close(MessageBoxResult.None);
+ if (_buttonConfigs == MessageBoxButton.OK)
+ {
+ Close(MessageBoxResult.OK);
+ }
+ Close(MessageBoxResult.Cancel);
}
private void OnYesButtonClick(object sender, RoutedEventArgs e)
{
- this.Close(MessageBoxResult.Yes);
+ Close(MessageBoxResult.Yes);
}
private void OnNoButtonClick(object sender, RoutedEventArgs e)
{
- this.Close(MessageBoxResult.No);
+ Close(MessageBoxResult.No);
}
private void OnOKButtonClick(object sender, RoutedEventArgs e)
{
- this.Close(MessageBoxResult.OK);
+ Close(MessageBoxResult.OK);
}
private void OnCancelButtonClick(object sender, RoutedEventArgs e)
{
- this.Close(MessageBoxResult.Cancel);
+ Close(MessageBoxResult.Cancel);
}
protected override void OnKeyUp(KeyEventArgs e)
{
base.OnKeyUp(e);
- if (e.Key == Key.Escape)
+ if (e.Key == Key.Escape && _buttonConfigs == MessageBoxButton.OK)
{
- this.Close(MessageBoxResult.None);
+ Close(MessageBoxResult.OK);
}
}
}
\ No newline at end of file