From 1fc1c26cb782ff544612e07ab59655aae880fc63 Mon Sep 17 00:00:00 2001 From: pr8x Date: Tue, 28 Feb 2023 12:38:29 +0100 Subject: [PATCH] Set IsReadOnly instead, use ConvertToInvariantString, Fix TextBox foreground on selected row --- .../Diagnostics/Views/MainView.xaml.cs | 5 ++- .../Views/PropertyValueEditorView.cs | 32 ++++++++++++------- .../Controls/TextBox.xaml | 1 + 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/Avalonia.Diagnostics/Diagnostics/Views/MainView.xaml.cs b/src/Avalonia.Diagnostics/Diagnostics/Views/MainView.xaml.cs index 7980aa215b..df5188b29b 100644 --- a/src/Avalonia.Diagnostics/Diagnostics/Views/MainView.xaml.cs +++ b/src/Avalonia.Diagnostics/Diagnostics/Views/MainView.xaml.cs @@ -1,7 +1,6 @@ using Avalonia.Controls; using Avalonia.Diagnostics.ViewModels; using Avalonia.Input; -using Avalonia.Interactivity; using Avalonia.Markup.Xaml; using Avalonia.Threading; @@ -18,7 +17,7 @@ namespace Avalonia.Diagnostics.Views public MainView() { InitializeComponent(); - AddHandler(KeyDownEvent, PreviewKeyDown, RoutingStrategies.Tunnel); + AddHandler(KeyUpEvent, PreviewKeyUp); _console = this.GetControl("console"); _consoleSplitter = this.GetControl("consoleSplitter"); _rootGrid = this.GetControl("rootGrid"); @@ -58,7 +57,7 @@ namespace Avalonia.Diagnostics.Views AvaloniaXamlLoader.Load(this); } - private void PreviewKeyDown(object? sender, KeyEventArgs e) + private void PreviewKeyUp(object? sender, KeyEventArgs e) { if (e.Key == Key.Escape) { diff --git a/src/Avalonia.Diagnostics/Diagnostics/Views/PropertyValueEditorView.cs b/src/Avalonia.Diagnostics/Diagnostics/Views/PropertyValueEditorView.cs index d20312a218..6e7729a350 100644 --- a/src/Avalonia.Diagnostics/Diagnostics/Views/PropertyValueEditorView.cs +++ b/src/Avalonia.Diagnostics/Diagnostics/Views/PropertyValueEditorView.cs @@ -10,7 +10,6 @@ using Avalonia.Data.Converters; using Avalonia.Diagnostics.Controls; using Avalonia.Diagnostics.ViewModels; using Avalonia.Input; -using Avalonia.Interactivity; using Avalonia.Layout; using Avalonia.Markup.Xaml.Converters; using Avalonia.Media; @@ -48,7 +47,7 @@ namespace Avalonia.Diagnostics.Views private static bool ImplementsInterface(Type type) { var interfaceType = typeof(TInterface); - return type == interfaceType || type.GetInterface(interfaceType.FullName!) != null; + return type == interfaceType || interfaceType.IsAssignableFrom(type); } private Control? UpdateControl() @@ -60,7 +59,8 @@ namespace Avalonia.Diagnostics.Views TControl CreateControl(AvaloniaProperty valueProperty, IValueConverter? converter = null, - Action? init = null) + Action? init = null, + AvaloniaProperty? readonlyProperty = null) where TControl : Control, new() { var control = new TControl(); @@ -75,7 +75,14 @@ namespace Avalonia.Diagnostics.Views ConverterParameter = propertyType }).DisposeWith(_cleanup); - control.IsEnabled = !Property.IsReadonly; + if (readonlyProperty != null) + { + control[readonlyProperty] = Property.IsReadonly; + } + else + { + control.IsEnabled = !Property.IsReadonly; + } return control; } @@ -93,7 +100,8 @@ namespace Avalonia.Diagnostics.Views n.Increment = 1; n.NumberFormat = new NumberFormatInfo { NumberDecimalDigits = 0 }; n.ParsingNumberStyle = NumberStyles.Integer; - }); + }, + readonlyProperty: NumericUpDown.IsReadOnlyProperty); if (propertyType == typeof(Color)) { @@ -117,7 +125,8 @@ namespace Avalonia.Diagnostics.Views Spacing = 2, Children = { el, tbl }, Background = Brushes.Transparent, - Cursor = new Cursor(StandardCursorType.Hand) + Cursor = new Cursor(StandardCursorType.Hand), + IsEnabled = !Property.IsReadonly }; var cv = new ColorView(); @@ -221,12 +230,13 @@ namespace Avalonia.Diagnostics.Views t => { t.Watermark = "(null)"; - }); + }, + readonlyProperty: TextBox.IsReadOnlyProperty); - tb.IsEnabled &= propertyType != typeof(object) && - StringConversionHelper.CanConvertFromString(propertyType); + tb.IsReadOnly |= propertyType == typeof(object) || + !StringConversionHelper.CanConvertFromString(propertyType); - if (tb.IsEnabled) + if (!tb.IsReadOnly) { tb.GetObservable(TextBox.TextProperty).Subscribe(t => { @@ -311,7 +321,7 @@ namespace Avalonia.Diagnostics.Views converter.GetType() == typeof(CollectionConverter)) return o.ToString(); - return converter.ConvertToString(o); + return converter.ConvertToInvariantString(o); } public static object? FromString(string str, Type type) diff --git a/src/Avalonia.Themes.Simple/Controls/TextBox.xaml b/src/Avalonia.Themes.Simple/Controls/TextBox.xaml index 8428e3aae7..0c7095f2f5 100644 --- a/src/Avalonia.Themes.Simple/Controls/TextBox.xaml +++ b/src/Avalonia.Themes.Simple/Controls/TextBox.xaml @@ -92,6 +92,7 @@ +