diff --git a/SukiUI.Demo/Features/ControlsLibrary/PropertyGridView.axaml b/SukiUI.Demo/Features/ControlsLibrary/PropertyGridView.axaml index 99a6faa10..efd35e490 100644 --- a/SukiUI.Demo/Features/ControlsLibrary/PropertyGridView.axaml +++ b/SukiUI.Demo/Features/ControlsLibrary/PropertyGridView.axaml @@ -1,27 +1,38 @@ + + + + - - - - - - + + + + + + + + + diff --git a/SukiUI.Demo/Features/ControlsLibrary/PropertyGridView.axaml.cs b/SukiUI.Demo/Features/ControlsLibrary/PropertyGridView.axaml.cs index 1c3857cbb..0ac9bc697 100644 --- a/SukiUI.Demo/Features/ControlsLibrary/PropertyGridView.axaml.cs +++ b/SukiUI.Demo/Features/ControlsLibrary/PropertyGridView.axaml.cs @@ -1,4 +1,7 @@ using Avalonia.Controls; +using Avalonia.Controls.Primitives; +using Avalonia.Interactivity; +using SukiUI.Controls; namespace SukiUI.Demo.Features.ControlsLibrary; @@ -8,4 +11,18 @@ public PropertyGridView() { InitializeComponent(); } + + private void ToggleButton_OnIsCheckedChanged(object? sender, RoutedEventArgs e) + { + if (sender is not ToggleButton toggleButton) + { + return; + } + + var resource = this.FindResource("PropertyGridTemplateSelector"); + if (resource is PropertyGridTemplateSelector templateSelector) + { + templateSelector.UseSukiHost = toggleButton.IsChecked == true; + } + } } \ No newline at end of file diff --git a/SukiUI/Controls/PropertyGrid/PropertyGridTemplateSelector.axaml.cs b/SukiUI/Controls/PropertyGrid/PropertyGridTemplateSelector.axaml.cs index 0836fc861..d1c5aaf16 100644 --- a/SukiUI/Controls/PropertyGrid/PropertyGridTemplateSelector.axaml.cs +++ b/SukiUI/Controls/PropertyGrid/PropertyGridTemplateSelector.axaml.cs @@ -1,4 +1,6 @@ -using Avalonia.Controls; +using System.Linq; +using System.Threading.Tasks; +using Avalonia.Controls; using Avalonia.Controls.Templates; using Avalonia.Interactivity; using Avalonia.Markup.Xaml; @@ -9,8 +11,10 @@ namespace SukiUI.Controls; public partial class PropertyGridTemplateSelector : ResourceDictionary, IDataTemplate { + public SukiDialogHost? SukiDialogHost { get; set; } + public bool UseSukiHost { get; set; } = true; - + public PropertyGridTemplateSelector() { InitializeComponent(); @@ -57,46 +61,80 @@ public bool Match(object? data) return false; } - if (ContainsKey(key) == false) + return ContainsKey(key) != false; + } + + private static void ShowSukiHostDialog(ISukiDialogManager manager, ComplexTypeViewModel viewModel) + { + manager + .CreateDialog() + .WithContent(new PropertyGridDialog() + { + DataContext = viewModel.Value + }) + .WithTitle(viewModel.DisplayName) + .Dismiss().ByClickingBackground() + .TryShow(); + } + + private static async Task ShowWindowDialogAsync(Control control) + { + var root = control.GetVisualRoot(); + if (root is not Window parentWindow || control.DataContext is not ComplexTypeViewModel childViewModel || childViewModel.Value is null) { - return false; + return; } - return true; + var window = new PropertyGridWindow() + { + DataContext = childViewModel.Value, + Title = childViewModel.DisplayName, + }; + + await window.ShowDialog(parentWindow); } - private async void OnMoreInfoClick(object sender, RoutedEventArgs e) + protected virtual async void OnMoreInfoClick(object sender, RoutedEventArgs e) { if (sender is not Control control) { return; } - // TODO: No longer possible to just statically use SukiHost to show dialogs. - // if (UseSukiHost) - // { - // if (control.DataContext is not ComplexTypeViewModel childViewModel || childViewModel.Value is null) - // { - // return; - // } - // SukiHost.ShowDialog(new PropertyGridDialog() - // { - // DataContext = childViewModel.Value - // }, true, true); - // } - else + + var sukiDialogHost = SukiDialogHost; + if (UseSukiHost) { - var root = control.GetVisualRoot(); - if (root is not Window parentWindow || control.DataContext is not ComplexTypeViewModel childViewModel || childViewModel.Value is null) + if (sukiDialogHost is not null) { - return; - } + if (control.DataContext is not ComplexTypeViewModel childViewModel || childViewModel.Value is null) + { + return; + } - var window = new PropertyGridWindow() + ShowSukiHostDialog(sukiDialogHost.Manager, childViewModel); + } + else { - DataContext = childViewModel, - }; + var root = control.GetVisualRoot(); + if (root is not SukiWindow parentWindow || control.DataContext is not ComplexTypeViewModel childViewModel || childViewModel.Value is null) + { + return; + } - await window.ShowDialog(parentWindow); + sukiDialogHost = parentWindow.Hosts.Where(p => p is SukiDialogHost).Cast().FirstOrDefault(); + if (sukiDialogHost is not null) + { + ShowSukiHostDialog(sukiDialogHost.Manager, childViewModel); + } + else + { + await ShowWindowDialogAsync(control); + } + } + } + else + { + await ShowWindowDialogAsync(control); } } } \ No newline at end of file diff --git a/SukiUI/Controls/PropertyGrid/PropertyGridWindow.axaml b/SukiUI/Controls/PropertyGrid/PropertyGridWindow.axaml index aae9fc462..c35052476 100644 --- a/SukiUI/Controls/PropertyGrid/PropertyGridWindow.axaml +++ b/SukiUI/Controls/PropertyGrid/PropertyGridWindow.axaml @@ -4,7 +4,6 @@ xmlns:controls="clr-namespace:SukiUI.Controls" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - Title="{Binding DisplayName}" Width="400" Height="500" d:DesignHeight="400" @@ -14,20 +13,18 @@ mc:Ignorable="d"> - - - - + + + - + - - - - - + + + +