From f6b4c8ef0dcd031cb415b8a35273fa2b58b212f7 Mon Sep 17 00:00:00 2001 From: Giuseppe Lippolis Date: Wed, 7 Jun 2023 15:43:43 +0200 Subject: [PATCH 1/3] feat(DevTools): Can be edit Brush if is Property is Null --- .../Diagnostics/Controls/BrushEditor.axaml | 21 +++ .../Diagnostics/Controls/BrushEditor.axaml.cs | 131 ++++++++++++++++++ .../Diagnostics/Controls/BrushEditor.cs | 94 ------------- .../Diagnostics/Views/MainWindow.xaml | 1 + 4 files changed, 153 insertions(+), 94 deletions(-) create mode 100644 src/Avalonia.Diagnostics/Diagnostics/Controls/BrushEditor.axaml create mode 100644 src/Avalonia.Diagnostics/Diagnostics/Controls/BrushEditor.axaml.cs delete mode 100644 src/Avalonia.Diagnostics/Diagnostics/Controls/BrushEditor.cs diff --git a/src/Avalonia.Diagnostics/Diagnostics/Controls/BrushEditor.axaml b/src/Avalonia.Diagnostics/Diagnostics/Controls/BrushEditor.axaml new file mode 100644 index 0000000000..7162be888f --- /dev/null +++ b/src/Avalonia.Diagnostics/Diagnostics/Controls/BrushEditor.axaml @@ -0,0 +1,21 @@ + + + + + + + diff --git a/src/Avalonia.Diagnostics/Diagnostics/Controls/BrushEditor.axaml.cs b/src/Avalonia.Diagnostics/Diagnostics/Controls/BrushEditor.axaml.cs new file mode 100644 index 0000000000..c75da84519 --- /dev/null +++ b/src/Avalonia.Diagnostics/Diagnostics/Controls/BrushEditor.axaml.cs @@ -0,0 +1,131 @@ +using System; +using System.Globalization; +using Avalonia.Controls; +using Avalonia.Controls.Metadata; +using Avalonia.Controls.Primitives; +using Avalonia.Input; +using Avalonia.Interactivity; +using Avalonia.Media; +using Avalonia.Media.Immutable; + +namespace Avalonia.Diagnostics.Controls +{ + [TemplatePart("PART_ClearButton", typeof(Button))] + partial class BrushEditor : TemplatedControl + { + private readonly EventHandler clearHandler; + private Button? _cleraButton = default; + private readonly ColorView _colorView = new() + { + HexInputAlphaPosition = AlphaComponentPosition.Leading, // Always match XAML + }; + + + public BrushEditor() + { + FlyoutBase.SetAttachedFlyout(this, new Flyout { Content = _colorView }); + _colorView.ColorChanged += (_, e) => Brush = new ImmutableSolidColorBrush(e.NewColor); + clearHandler = (s, e) => Brush = default; + } + + protected override Type StyleKeyOverride => typeof(BrushEditor); + + protected override void OnApplyTemplate(TemplateAppliedEventArgs e) + { + base.OnApplyTemplate(e); + if (_cleraButton is not null) + { + _cleraButton.Click -= clearHandler; + } + _cleraButton = e.NameScope.Find