Browse Source

Set IsReadOnly instead, use ConvertToInvariantString, Fix TextBox foreground on selected row

pull/10368/head
pr8x 4 years ago
parent
commit
1fc1c26cb7
  1. 5
      src/Avalonia.Diagnostics/Diagnostics/Views/MainView.xaml.cs
  2. 32
      src/Avalonia.Diagnostics/Diagnostics/Views/PropertyValueEditorView.cs
  3. 1
      src/Avalonia.Themes.Simple/Controls/TextBox.xaml

5
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<ConsoleView>("console");
_consoleSplitter = this.GetControl<GridSplitter>("consoleSplitter");
_rootGrid = this.GetControl<Grid>("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)
{

32
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<TInterface>(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<TControl>(AvaloniaProperty valueProperty,
IValueConverter? converter = null,
Action<TControl>? init = null)
Action<TControl>? 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)

1
src/Avalonia.Themes.Simple/Controls/TextBox.xaml

@ -92,6 +92,7 @@
<Setter Property="CaretBrush" Value="{DynamicResource ThemeForegroundBrush}" />
<Setter Property="Background" Value="{DynamicResource ThemeBackgroundBrush}" />
<Setter Property="BorderBrush" Value="{DynamicResource ThemeBorderMidBrush}" />
<Setter Property="Foreground" Value="{DynamicResource ThemeForegroundBrush}" />
<Setter Property="BorderThickness" Value="{DynamicResource ThemeBorderThickness}" />
<Setter Property="SelectionBrush" Value="{DynamicResource HighlightBrush}" />
<Setter Property="SelectionForegroundBrush" Value="{DynamicResource HighlightForegroundBrush}" />

Loading…
Cancel
Save