From abb1bffaeb631a764c011c3b93d43e7c2d956fe3 Mon Sep 17 00:00:00 2001 From: rabbitism Date: Wed, 10 Jan 2024 00:45:03 +0800 Subject: [PATCH 01/11] feat: start --- src/Ursa/Controls/MessageBox/MessageBox.cs | 12 ++++++++++++ src/Ursa/Controls/MessageBox/MessageBoxWindow.cs | 15 +++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 src/Ursa/Controls/MessageBox/MessageBox.cs create mode 100644 src/Ursa/Controls/MessageBox/MessageBoxWindow.cs diff --git a/src/Ursa/Controls/MessageBox/MessageBox.cs b/src/Ursa/Controls/MessageBox/MessageBox.cs new file mode 100644 index 00000000..0558ec16 --- /dev/null +++ b/src/Ursa/Controls/MessageBox/MessageBox.cs @@ -0,0 +1,12 @@ +using Avalonia; +using Avalonia.Controls.ApplicationLifetimes; + +namespace Ursa.Controls.MessageBox; + +public static class MessageBox +{ + public static async Task ShowAsync(string message) + { + var messageWindow = new MessageBoxWindow(); + } +} \ No newline at end of file diff --git a/src/Ursa/Controls/MessageBox/MessageBoxWindow.cs b/src/Ursa/Controls/MessageBox/MessageBoxWindow.cs new file mode 100644 index 00000000..da1613d2 --- /dev/null +++ b/src/Ursa/Controls/MessageBox/MessageBoxWindow.cs @@ -0,0 +1,15 @@ +using Avalonia.Controls; +using Avalonia.Platform; + +namespace Ursa.Controls.MessageBox; + +public class MessageBoxWindow: Window +{ + protected override Type StyleKeyOverride => typeof(MessageBoxWindow); + + static MessageBoxWindow() + { + ExtendClientAreaChromeHintsProperty.OverrideDefaultValue(ExtendClientAreaChromeHints + .NoChrome); + } +} \ No newline at end of file From 81d54d3b28cd48f5ff016fe380222c0fa6706701 Mon Sep 17 00:00:00 2001 From: rabbitism Date: Wed, 10 Jan 2024 22:38:50 +0800 Subject: [PATCH 02/11] feat: add default template. --- demo/Ursa.Demo/Models/MenuKeys.cs | 1 + demo/Ursa.Demo/Pages/MessageBoxDemo.axaml | 13 ++++++ demo/Ursa.Demo/Pages/MessageBoxDemo.axaml.cs | 15 +++++++ .../Ursa.Demo/ViewModels/MainViewViewModel.cs | 1 + demo/Ursa.Demo/ViewModels/MenuViewModel.cs | 1 + .../ViewModels/MessageBoxDemoViewModel.cs | 22 ++++++++++ demo/Ursa.Demo/Views/MainWindow.axaml | 2 + .../Controls/MessageBoxWindow.axaml | 41 +++++++++++++++++++ src/Ursa.Themes.Semi/Controls/_index.axaml | 1 + src/Ursa/Controls/MessageBox/MessageBox.cs | 20 ++++++++- .../Controls/MessageBox/MessageBoxWindow.cs | 5 +-- 11 files changed, 117 insertions(+), 5 deletions(-) create mode 100644 demo/Ursa.Demo/Pages/MessageBoxDemo.axaml create mode 100644 demo/Ursa.Demo/Pages/MessageBoxDemo.axaml.cs create mode 100644 demo/Ursa.Demo/ViewModels/MessageBoxDemoViewModel.cs create mode 100644 src/Ursa.Themes.Semi/Controls/MessageBoxWindow.axaml diff --git a/demo/Ursa.Demo/Models/MenuKeys.cs b/demo/Ursa.Demo/Models/MenuKeys.cs index 8532a7f2..1b88691b 100644 --- a/demo/Ursa.Demo/Models/MenuKeys.cs +++ b/demo/Ursa.Demo/Models/MenuKeys.cs @@ -13,6 +13,7 @@ public static class MenuKeys public const string MenuKeyIconButton = "IconButton"; public const string MenuKeyKeyGestureInput = "KeyGestureInput"; public const string MenuKeyLoading = "Loading"; + public const string MenuKeyMessageBox = "MessageBox"; public const string MenuKeyNavigation = "Navigation"; public const string MenuKeyPagination = "Pagination"; public const string MenuKeyTagInput = "TagInput"; diff --git a/demo/Ursa.Demo/Pages/MessageBoxDemo.axaml b/demo/Ursa.Demo/Pages/MessageBoxDemo.axaml new file mode 100644 index 00000000..e9f6213d --- /dev/null +++ b/demo/Ursa.Demo/Pages/MessageBoxDemo.axaml @@ -0,0 +1,13 @@ + + + + + diff --git a/demo/Ursa.Demo/Pages/MessageBoxDemo.axaml.cs b/demo/Ursa.Demo/Pages/MessageBoxDemo.axaml.cs new file mode 100644 index 00000000..0b5cf400 --- /dev/null +++ b/demo/Ursa.Demo/Pages/MessageBoxDemo.axaml.cs @@ -0,0 +1,15 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Markup.Xaml; +using Ursa.Demo.ViewModels; + +namespace Ursa.Demo.Pages; + +public partial class MessageBoxDemo : UserControl +{ + public MessageBoxDemo() + { + InitializeComponent(); + this.DataContext = new MessageBoxDemoViewModel(); + } +} \ No newline at end of file diff --git a/demo/Ursa.Demo/ViewModels/MainViewViewModel.cs b/demo/Ursa.Demo/ViewModels/MainViewViewModel.cs index d2c59ba1..83fea1a9 100644 --- a/demo/Ursa.Demo/ViewModels/MainViewViewModel.cs +++ b/demo/Ursa.Demo/ViewModels/MainViewViewModel.cs @@ -35,6 +35,7 @@ private void OnNavigation(MainViewViewModel vm, string s) MenuKeys.MenuKeyIpBox => new IPv4BoxDemoViewModel(), MenuKeys.MenuKeyKeyGestureInput => new KeyGestureInputDemoViewModel(), MenuKeys.MenuKeyLoading => new LoadingDemoViewModel(), + MenuKeys.MenuKeyMessageBox => new MessageBoxDemoViewModel(), MenuKeys.MenuKeyNavigation => new NavigationMenuDemoViewModel(), MenuKeys.MenuKeyPagination => new PaginationDemoViewModel(), MenuKeys.MenuKeyTagInput => new TagInputDemoViewModel(), diff --git a/demo/Ursa.Demo/ViewModels/MenuViewModel.cs b/demo/Ursa.Demo/ViewModels/MenuViewModel.cs index b2f04b02..c3214991 100644 --- a/demo/Ursa.Demo/ViewModels/MenuViewModel.cs +++ b/demo/Ursa.Demo/ViewModels/MenuViewModel.cs @@ -22,6 +22,7 @@ public MenuViewModel() new() { MenuHeader = "IPv4Box", Key = MenuKeys.MenuKeyIpBox }, new() { MenuHeader = "KeyGestureInput", Key = MenuKeys.MenuKeyKeyGestureInput }, new() { MenuHeader = "Loading", Key = MenuKeys.MenuKeyLoading }, + new() { MenuHeader = "Message Box", Key = MenuKeys.MenuKeyMessageBox }, new() { MenuHeader = "Navigation", Key = MenuKeys.MenuKeyNavigation }, new() { MenuHeader = "Pagination", Key = MenuKeys.MenuKeyPagination }, new() { MenuHeader = "TagInput", Key = MenuKeys.MenuKeyTagInput }, diff --git a/demo/Ursa.Demo/ViewModels/MessageBoxDemoViewModel.cs b/demo/Ursa.Demo/ViewModels/MessageBoxDemoViewModel.cs new file mode 100644 index 00000000..809b95ac --- /dev/null +++ b/demo/Ursa.Demo/ViewModels/MessageBoxDemoViewModel.cs @@ -0,0 +1,22 @@ +using System.Threading.Tasks; +using System.Windows.Input; +using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; +using Ursa.Controls; + +namespace Ursa.Demo.ViewModels; + +public class MessageBoxDemoViewModel: ObservableObject +{ + public ICommand DefaultMessageBoxCommand { get; set; } + + public MessageBoxDemoViewModel() + { + DefaultMessageBoxCommand = new AsyncRelayCommand(OnDefaultMessageAsync); + } + + private async Task OnDefaultMessageAsync() + { + await MessageBox.ShowAsync("Hello Message Box"); + } +} \ No newline at end of file diff --git a/demo/Ursa.Demo/Views/MainWindow.axaml b/demo/Ursa.Demo/Views/MainWindow.axaml index 054e043a..5504e4ac 100644 --- a/demo/Ursa.Demo/Views/MainWindow.axaml +++ b/demo/Ursa.Demo/Views/MainWindow.axaml @@ -10,6 +10,8 @@ d:DesignHeight="450" d:DesignWidth="800" x:CompileBindings="True" + ExtendClientAreaTitleBarHeightHint="48" + ExtendClientAreaToDecorationsHint="True" x:DataType="viewModels:MainWindowViewModel" Icon="/Assets/Ursa.ico" mc:Ignorable="d"> diff --git a/src/Ursa.Themes.Semi/Controls/MessageBoxWindow.axaml b/src/Ursa.Themes.Semi/Controls/MessageBoxWindow.axaml new file mode 100644 index 00000000..82ff0182 --- /dev/null +++ b/src/Ursa.Themes.Semi/Controls/MessageBoxWindow.axaml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Ursa.Themes.Semi/Controls/_index.axaml b/src/Ursa.Themes.Semi/Controls/_index.axaml index f3b1ac57..1fbacb9f 100644 --- a/src/Ursa.Themes.Semi/Controls/_index.axaml +++ b/src/Ursa.Themes.Semi/Controls/_index.axaml @@ -11,6 +11,7 @@ + diff --git a/src/Ursa/Controls/MessageBox/MessageBox.cs b/src/Ursa/Controls/MessageBox/MessageBox.cs index 0558ec16..eccf2562 100644 --- a/src/Ursa/Controls/MessageBox/MessageBox.cs +++ b/src/Ursa/Controls/MessageBox/MessageBox.cs @@ -1,12 +1,28 @@ using Avalonia; using Avalonia.Controls.ApplicationLifetimes; -namespace Ursa.Controls.MessageBox; +namespace Ursa.Controls; public static class MessageBox { public static async Task ShowAsync(string message) { - var messageWindow = new MessageBoxWindow(); + var messageWindow = new MessageBoxWindow() + { + Content = message + }; + var lifetime = Application.Current?.ApplicationLifetime; + if (lifetime is IClassicDesktopStyleApplicationLifetime classLifetime) + { + var main = classLifetime.MainWindow; + if (main is null) + { + messageWindow.Show(); + } + else + { + await messageWindow.ShowDialog(main); + } + } } } \ No newline at end of file diff --git a/src/Ursa/Controls/MessageBox/MessageBoxWindow.cs b/src/Ursa/Controls/MessageBox/MessageBoxWindow.cs index da1613d2..5d2dbef3 100644 --- a/src/Ursa/Controls/MessageBox/MessageBoxWindow.cs +++ b/src/Ursa/Controls/MessageBox/MessageBoxWindow.cs @@ -1,7 +1,7 @@ using Avalonia.Controls; using Avalonia.Platform; -namespace Ursa.Controls.MessageBox; +namespace Ursa.Controls; public class MessageBoxWindow: Window { @@ -9,7 +9,6 @@ public class MessageBoxWindow: Window static MessageBoxWindow() { - ExtendClientAreaChromeHintsProperty.OverrideDefaultValue(ExtendClientAreaChromeHints - .NoChrome); + } } \ No newline at end of file From 66894aa56924ed18cdcaa8a75ff15dc5239e724d Mon Sep 17 00:00:00 2001 From: rabbitism Date: Thu, 11 Jan 2024 02:41:58 +0800 Subject: [PATCH 03/11] feat: add default buttons. --- .../ViewModels/MessageBoxDemoViewModel.cs | 2 +- demo/Ursa.Demo/Views/MainWindow.axaml | 2 - .../Controls/MessageBoxWindow.axaml | 63 ++++++---- src/Ursa/Controls/MessageBox/MessageBox.cs | 10 +- .../Controls/MessageBox/MessageBoxButton.cs | 9 ++ .../Controls/MessageBox/MessageBoxResult.cs | 10 ++ .../Controls/MessageBox/MessageBoxWindow.cs | 117 ++++++++++++++++++ 7 files changed, 183 insertions(+), 30 deletions(-) create mode 100644 src/Ursa/Controls/MessageBox/MessageBoxButton.cs create mode 100644 src/Ursa/Controls/MessageBox/MessageBoxResult.cs diff --git a/demo/Ursa.Demo/ViewModels/MessageBoxDemoViewModel.cs b/demo/Ursa.Demo/ViewModels/MessageBoxDemoViewModel.cs index 809b95ac..3d950400 100644 --- a/demo/Ursa.Demo/ViewModels/MessageBoxDemoViewModel.cs +++ b/demo/Ursa.Demo/ViewModels/MessageBoxDemoViewModel.cs @@ -17,6 +17,6 @@ public MessageBoxDemoViewModel() private async Task OnDefaultMessageAsync() { - await MessageBox.ShowAsync("Hello Message Box"); + var result = await MessageBox.ShowAsync("Hello Message Box"); } } \ No newline at end of file diff --git a/demo/Ursa.Demo/Views/MainWindow.axaml b/demo/Ursa.Demo/Views/MainWindow.axaml index 5504e4ac..054e043a 100644 --- a/demo/Ursa.Demo/Views/MainWindow.axaml +++ b/demo/Ursa.Demo/Views/MainWindow.axaml @@ -10,8 +10,6 @@ d:DesignHeight="450" d:DesignWidth="800" x:CompileBindings="True" - ExtendClientAreaTitleBarHeightHint="48" - ExtendClientAreaToDecorationsHint="True" x:DataType="viewModels:MainWindowViewModel" Icon="/Assets/Ursa.ico" mc:Ignorable="d"> diff --git a/src/Ursa.Themes.Semi/Controls/MessageBoxWindow.axaml b/src/Ursa.Themes.Semi/Controls/MessageBoxWindow.axaml index 82ff0182..a2c496f4 100644 --- a/src/Ursa.Themes.Semi/Controls/MessageBoxWindow.axaml +++ b/src/Ursa.Themes.Semi/Controls/MessageBoxWindow.axaml @@ -1,39 +1,52 @@ - - - + + + + - - - - - - - - + + + + + + + - - - - - - + + + + + + + + diff --git a/demo/Ursa.Demo/ViewModels/MessageBoxDemoViewModel.cs b/demo/Ursa.Demo/ViewModels/MessageBoxDemoViewModel.cs index 3d950400..4afcb648 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 a2c496f4..b10410b6 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 @@ - - + + + - - - - - - + + - + ColumnDefinitions="Auto, *"> + + + + + + + + + + + diff --git a/src/Ursa.Themes.Semi/Themes/Shared/MessageBoxWindow.axaml b/src/Ursa.Themes.Semi/Themes/Shared/MessageBoxWindow.axaml new file mode 100644 index 00000000..bb58b3ff --- /dev/null +++ b/src/Ursa.Themes.Semi/Themes/Shared/MessageBoxWindow.axaml @@ -0,0 +1,9 @@ + + + M12 23C18.0751 23 23 18.0751 23 12C23 5.92487 18.0751 1 12 1C5.92487 1 1 5.92487 1 12C1 18.0751 5.92487 23 12 23ZM11.8281 14.6094C10.9688 14.6094 10.5391 14.0723 10.5391 13.3691C10.5391 12.3242 11.0566 11.6504 12.2676 10.7324C12.2894 10.7158 12.3111 10.6993 12.3326 10.6829C13.1573 10.0555 13.7324 9.61807 13.7324 8.82812C13.7324 7.93945 12.9023 7.42188 11.9746 7.42188C11.2129 7.42188 10.627 7.70508 10.168 8.30078C9.83594 8.64258 9.57227 8.82812 9.12305 8.82812C8.38086 8.82812 8 8.31055 8 7.71484C8 7.10938 8.3418 6.49414 8.87891 6.02539C9.60156 5.40039 10.7539 5 12.2773 5C14.9922 5 16.8965 6.33789 16.8965 8.64258C16.8965 10.3223 15.8906 11.1328 14.709 11.9531C13.9082 12.5391 13.5273 12.8809 13.2246 13.5742L13.2238 13.5756C12.8922 14.1609 12.638 14.6094 11.8281 14.6094ZM11.8086 18.7695C10.8711 18.7695 10.0996 18.1641 10.0996 17.2266C10.0996 16.2891 10.8711 15.6836 11.8086 15.6836C12.7461 15.6836 13.5078 16.2891 13.5078 17.2266C13.5078 18.1641 12.7461 18.7695 11.8086 18.7695Z + M12 23C18.0751 23 23 18.0751 23 12C23 5.92487 18.0751 1 12 1C5.92487 1 1 5.92487 1 12C1 18.0751 5.92487 23 12 23ZM14 7C14 8.10457 13.1046 9 12 9C10.8954 9 10 8.10457 10 7C10 5.89543 10.8954 5 12 5C13.1046 5 14 5.89543 14 7ZM9 10.75C9 10.3358 9.33579 10 9.75 10H12.5C13.0523 10 13.5 10.4477 13.5 11V16.5H14.25C14.6642 16.5 15 16.8358 15 17.25C15 17.6642 14.6642 18 14.25 18H9.75C9.33579 18 9 17.6642 9 17.25C9 16.8358 9.33579 16.5 9.75 16.5H10.5V11.5H9.75C9.33579 11.5 9 11.1642 9 10.75Z + M10.2268 2.3986L1.52616 19.0749C0.831449 20.4064 1.79747 22 3.29933 22H20.7007C22.2025 22 23.1686 20.4064 22.4739 19.0749L13.7732 2.3986C13.0254 0.965441 10.9746 0.965442 10.2268 2.3986ZM13.1415 14.0101C13.0603 14.5781 12.5739 15 12.0001 15C11.4263 15 10.9398 14.5781 10.8586 14.0101L10.2829 9.97992C10.1336 8.93495 10.9445 8.00002 12.0001 8.00002C13.0556 8.00002 13.8665 8.93495 13.7172 9.97992L13.1415 14.0101ZM13.5001 18.5C13.5001 19.3284 12.8285 20 12.0001 20C11.1716 20 10.5001 19.3284 10.5001 18.5C10.5001 17.6716 11.1716 17 12.0001 17C12.8285 17 13.5001 17.6716 13.5001 18.5Z + M12 23C18.0751 23 23 18.0751 23 12C23 5.92487 18.0751 1 12 1C5.92487 1 1 5.92487 1 12C1 18.0751 5.92487 23 12 23ZM17.0352 16.8626C16.4597 17.4585 15.5101 17.4751 14.9142 16.8996L12.0368 14.121L9.25822 16.9984C8.68274 17.5943 7.73314 17.6109 7.13722 17.0354C6.5413 16.4599 6.52472 15.5103 7.1002 14.9144L9.87883 12.037L7.00147 9.2584C6.40555 8.68293 6.38897 7.73332 6.96445 7.1374C7.53992 6.54148 8.48953 6.52491 9.08545 7.10038L11.9628 9.87901L14.7414 7.00165C15.3169 6.40573 16.2665 6.38916 16.8624 6.96463C17.4584 7.54011 17.4749 8.48971 16.8995 9.08563L14.1208 11.963L16.9982 14.7416C17.5941 15.3171 17.6107 16.2667 17.0352 16.8626Z + M12 23C18.0751 23 23 18.0751 23 12C23 5.92487 18.0751 1 12 1C5.92487 1 1 5.92487 1 12C1 18.0751 5.92487 23 12 23ZM17.8831 9.82235L11.6854 17.4112C11.4029 17.7806 10.965 17.9981 10.5 18C10.035 18.0019 9.59533 17.788 9.30982 17.421L5.81604 13.4209C5.30744 12.767 5.42524 11.8246 6.07916 11.316C6.73308 10.8074 7.67549 10.9252 8.1841 11.5791L10.4838 14.0439L15.5 8C16.0032 7.34193 16.9446 7.21641 17.6027 7.71964C18.2608 8.22287 18.3863 9.16428 17.8831 9.82235Z + diff --git a/src/Ursa.Themes.Semi/Themes/Shared/_index.axaml b/src/Ursa.Themes.Semi/Themes/Shared/_index.axaml index 3d93ea53..d26e06a6 100644 --- a/src/Ursa.Themes.Semi/Themes/Shared/_index.axaml +++ b/src/Ursa.Themes.Semi/Themes/Shared/_index.axaml @@ -8,6 +8,7 @@ + diff --git a/src/Ursa/Controls/MessageBox/MessageBox.cs b/src/Ursa/Controls/MessageBox/MessageBox.cs index 1822d792..ac2c466e 100644 --- a/src/Ursa/Controls/MessageBox/MessageBox.cs +++ b/src/Ursa/Controls/MessageBox/MessageBox.cs @@ -1,15 +1,23 @@ using Avalonia; +using Avalonia.Controls; using Avalonia.Controls.ApplicationLifetimes; +using Avalonia.Controls.Notifications; namespace Ursa.Controls; public static class MessageBox { - public static async Task ShowAsync(string message) + public static async Task ShowAsync( + string message, + string? title = null, + MessageBoxIcon icon = MessageBoxIcon.None, + MessageBoxButton button = MessageBoxButton.OKCancel) { - var messageWindow = new MessageBoxWindow() + var messageWindow = new MessageBoxWindow(button) { - Content = message + Content = message, + Title = title, + MessageIcon = icon, }; var lifetime = Application.Current?.ApplicationLifetime; if (lifetime is IClassicDesktopStyleApplicationLifetime classLifetime) @@ -32,31 +40,20 @@ public static async Task ShowAsync(string message) } } - public static async Task ShowAsync(string message, string title, MessageBoxButton button) + public static async Task ShowAsync( + Window owner, + string message, + string title, + MessageBoxIcon icon = MessageBoxIcon.None, + MessageBoxButton button = MessageBoxButton.OKCancel) { var messageWindow = new MessageBoxWindow(button) { Content = message, - Title = title + Title = title, + MessageIcon = icon, }; - 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; - } + var result = await messageWindow.ShowDialog(owner); + return result; } } \ No newline at end of file diff --git a/src/Ursa/Controls/MessageBox/MessageBoxIcon.cs b/src/Ursa/Controls/MessageBox/MessageBoxIcon.cs new file mode 100644 index 00000000..be3639d1 --- /dev/null +++ b/src/Ursa/Controls/MessageBox/MessageBoxIcon.cs @@ -0,0 +1,15 @@ +namespace Ursa.Controls; + +public enum MessageBoxIcon +{ + Asterisk, // Same as Information + Error, + Exclamation, // Same as Warning + Hand, // Same as Error + Information, + None, + Question, + Stop, // Same as Error + Warning, + Success, +} \ No newline at end of file diff --git a/src/Ursa/Controls/MessageBox/MessageBoxWindow.cs b/src/Ursa/Controls/MessageBox/MessageBoxWindow.cs index 259bf05c..18fb7fb5 100644 --- a/src/Ursa/Controls/MessageBox/MessageBoxWindow.cs +++ b/src/Ursa/Controls/MessageBox/MessageBoxWindow.cs @@ -1,3 +1,4 @@ +using Avalonia; using Avalonia.Controls; using Avalonia.Controls.Metadata; using Avalonia.Controls.Primitives; @@ -30,9 +31,13 @@ public class MessageBoxWindow: Window protected override Type StyleKeyOverride => typeof(MessageBoxWindow); - static MessageBoxWindow() + public static readonly StyledProperty MessageIconProperty = AvaloniaProperty.Register( + nameof(MessageIcon)); + + public MessageBoxIcon MessageIcon { - + get => GetValue(MessageIconProperty); + set => SetValue(MessageIconProperty, value); } public MessageBoxWindow() From 5a41e0e566f2213672b6c245f6f3afc465147b4d Mon Sep 17 00:00:00 2001 From: Zhang Dian <54255897+zdpcdt@users.noreply.github.com> Date: Thu, 11 Jan 2024 23:10:12 +0800 Subject: [PATCH 06/11] fix: order of buttons. --- .../Controls/MessageBoxWindow.axaml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Ursa.Themes.Semi/Controls/MessageBoxWindow.axaml b/src/Ursa.Themes.Semi/Controls/MessageBoxWindow.axaml index fd00509a..a3defb54 100644 --- a/src/Ursa.Themes.Semi/Controls/MessageBoxWindow.axaml +++ b/src/Ursa.Themes.Semi/Controls/MessageBoxWindow.axaml @@ -80,25 +80,25 @@ HorizontalAlignment="Right" Orientation="Horizontal">