From b91df127eaaeec4972e0035fb4602a7666cc4a64 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Sat, 19 Jan 2019 01:09:58 +0100 Subject: [PATCH] Remove :valid and :invalid pseudoclasses. `:valid` and `:invalid` pseudoclasses are being added to all `ContentControls` simply in order to show/hide the `ContentPresenter` in `CheckBox`. Instead of this, add some `ObjectConverters` and use them to set the visibility of the `ContentPresenter.` Also renamed the converters in `StringConverters` to add an `Is` prefix as the `ObjectConverters` didn't look right as just `Null` and `NotNull`. --- .../Data/Converters/ObjectConverters.cs | 24 +++++++++++++++++++ .../Data/Converters/StringConverters.cs | 4 ++-- src/Avalonia.Controls/ContentControl.cs | 2 -- src/Avalonia.Themes.Default/CheckBox.xaml | 9 ++++--- src/Avalonia.Themes.Default/TextBox.xaml | 4 ++-- 5 files changed, 32 insertions(+), 11 deletions(-) create mode 100644 src/Avalonia.Base/Data/Converters/ObjectConverters.cs diff --git a/src/Avalonia.Base/Data/Converters/ObjectConverters.cs b/src/Avalonia.Base/Data/Converters/ObjectConverters.cs new file mode 100644 index 0000000000..3cadfd5b47 --- /dev/null +++ b/src/Avalonia.Base/Data/Converters/ObjectConverters.cs @@ -0,0 +1,24 @@ +// Copyright (c) The Avalonia Project. All rights reserved. +// Licensed under the MIT license. See licence.md file in the project root for full license information. + + +namespace Avalonia.Data.Converters +{ + /// + /// Provides a set of useful s for working with objects. + /// + public static class ObjectConverters + { + /// + /// A value converter that returns true if the input object is a null reference. + /// + public static readonly IValueConverter IsNull = + new FuncValueConverter(x => x is null); + + /// + /// A value converter that returns true if the input object is not null. + /// + public static readonly IValueConverter IsNotNull = + new FuncValueConverter(x => !(x is null)); + } +} diff --git a/src/Avalonia.Base/Data/Converters/StringConverters.cs b/src/Avalonia.Base/Data/Converters/StringConverters.cs index 0101cf5d29..42eb8e1d81 100644 --- a/src/Avalonia.Base/Data/Converters/StringConverters.cs +++ b/src/Avalonia.Base/Data/Converters/StringConverters.cs @@ -12,13 +12,13 @@ namespace Avalonia.Data.Converters /// /// A value converter that returns true if the input string is null or an empty string. /// - public static readonly IValueConverter NullOrEmpty = + public static readonly IValueConverter IsNullOrEmpty = new FuncValueConverter(string.IsNullOrEmpty); /// /// A value converter that returns true if the input string is not null or empty. /// - public static readonly IValueConverter NotNullOrEmpty = + public static readonly IValueConverter IsNotNullOrEmpty = new FuncValueConverter(x => !string.IsNullOrEmpty(x)); } } diff --git a/src/Avalonia.Controls/ContentControl.cs b/src/Avalonia.Controls/ContentControl.cs index 20ec581108..6da6da54a5 100644 --- a/src/Avalonia.Controls/ContentControl.cs +++ b/src/Avalonia.Controls/ContentControl.cs @@ -45,8 +45,6 @@ namespace Avalonia.Controls static ContentControl() { ContentControlMixin.Attach(ContentProperty, x => x.LogicalChildren); - PseudoClass(ContentProperty, x => x != null, ":valid"); - PseudoClass(ContentProperty, x => x == null, ":invalid"); } /// diff --git a/src/Avalonia.Themes.Default/CheckBox.xaml b/src/Avalonia.Themes.Default/CheckBox.xaml index e2301b9b09..f87ae2674f 100644 --- a/src/Avalonia.Themes.Default/CheckBox.xaml +++ b/src/Avalonia.Themes.Default/CheckBox.xaml @@ -1,9 +1,10 @@ - + - diff --git a/src/Avalonia.Themes.Default/TextBox.xaml b/src/Avalonia.Themes.Default/TextBox.xaml index 90100c2f2b..6741bdc7d9 100644 --- a/src/Avalonia.Themes.Default/TextBox.xaml +++ b/src/Avalonia.Themes.Default/TextBox.xaml @@ -23,7 +23,7 @@ Path="UseFloatingWatermark"/> + Converter="{x:Static StringConverters.IsNotNullOrEmpty}"/> @@ -36,7 +36,7 @@ + IsVisible="{TemplateBinding Text, Converter={x:Static StringConverters.IsNullOrEmpty}}"/>