diff --git a/src/Avalonia.Controls/ContentControl.cs b/src/Avalonia.Controls/ContentControl.cs index 6da6da54a5..f9241956bd 100644 --- a/src/Avalonia.Controls/ContentControl.cs +++ b/src/Avalonia.Controls/ContentControl.cs @@ -45,6 +45,8 @@ 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.Controls/TreeViewItem.cs b/src/Avalonia.Controls/TreeViewItem.cs index c5d3313117..4d229390cb 100644 --- a/src/Avalonia.Controls/TreeViewItem.cs +++ b/src/Avalonia.Controls/TreeViewItem.cs @@ -32,24 +32,24 @@ namespace Avalonia.Controls ListBoxItem.IsSelectedProperty.AddOwner(); /// - /// Defines the property. + /// Defines the property. /// - public static readonly DirectProperty DepthProperty = + public static readonly DirectProperty LevelProperty = AvaloniaProperty.RegisterDirect( - nameof(Depth), o => o.Depth); + nameof(Level), o => o.Level); private static readonly ITemplate DefaultPanel = new FuncTemplate(() => new StackPanel()); private TreeView _treeView; private bool _isExpanded; - private int _depth; + private int _level; /// /// Initializes static members of the class. /// static TreeViewItem() - { + { SelectableMixin.Attach(IsSelectedProperty); FocusableProperty.OverrideDefaultValue(true); ItemsPanelProperty.OverrideDefaultValue(DefaultPanel); @@ -74,12 +74,12 @@ namespace Avalonia.Controls } /// - /// Gets or sets the depth of the item. + /// Gets the level/indentation of the item. /// - public int Depth + public int Level { - get { return _depth; } - private set { SetAndRaise(DepthProperty, ref _depth, value); } + get { return _level; } + private set { SetAndRaise(LevelProperty, ref _level, value); } } /// @@ -106,7 +106,7 @@ namespace Avalonia.Controls base.OnAttachedToLogicalTree(e); _treeView = this.GetLogicalAncestors().OfType().FirstOrDefault(); - Depth = this.CalculateDistanceFromLogicalParent() - 1; + Level = CalculateDistanceFromLogicalParent(this) - 1; if (ItemTemplate == null && _treeView?.ItemTemplate != null) { @@ -145,5 +145,18 @@ namespace Avalonia.Controls // Don't call base.OnKeyDown - let events bubble up to containing TreeView. } + + private static int CalculateDistanceFromLogicalParent(ILogical logical, int @default = -1) where T : class + { + var result = 0; + + while (logical != null && logical.GetType() != typeof(T)) + { + ++result; + logical = logical.LogicalParent; + } + + return logical != null ? result : @default; + } } } diff --git a/src/Avalonia.Styling/LogicalTree/LogicalExtensions.cs b/src/Avalonia.Styling/LogicalTree/LogicalExtensions.cs index 47550a876d..276ea6c060 100644 --- a/src/Avalonia.Styling/LogicalTree/LogicalExtensions.cs +++ b/src/Avalonia.Styling/LogicalTree/LogicalExtensions.cs @@ -87,20 +87,5 @@ namespace Avalonia.LogicalTree { return target.GetLogicalAncestors().Any(x => x == logical); } - - public static int CalculateDistanceFromLogicalParent(this ILogical logical, int @default = -1) where T : class - { - Contract.Requires(logical != null); - - var result = 0; - - while (logical != null && logical.GetType() != typeof(T)) - { - ++result; - logical = logical.LogicalParent; - } - - return logical != null ? result : @default; - } } } diff --git a/src/Avalonia.Styling/Styling/PropertyEqualsSelector.cs b/src/Avalonia.Styling/Styling/PropertyEqualsSelector.cs index 57d5ad9271..25f12ffa57 100644 --- a/src/Avalonia.Styling/Styling/PropertyEqualsSelector.cs +++ b/src/Avalonia.Styling/Styling/PropertyEqualsSelector.cs @@ -60,7 +60,7 @@ namespace Avalonia.Styling builder.Append(_property.Name); builder.Append('='); - builder.Append(_value); + builder.Append(_value ?? string.Empty); builder.Append(']'); _selectorString = builder.ToString(); @@ -78,11 +78,11 @@ namespace Avalonia.Styling } else if (subscribe) { - return new SelectorMatch(control.GetObservable(_property).Select(v => Equals(v, _value))); + return new SelectorMatch(control.GetObservable(_property).Select(v => Equals(v ?? string.Empty, _value))); } else { - return new SelectorMatch(control.GetValue(_property).Equals(_value)); + return new SelectorMatch((control.GetValue(_property) ?? string.Empty).Equals(_value)); } } diff --git a/src/Avalonia.Themes.Default/Accents/BaseLight.xaml b/src/Avalonia.Themes.Default/Accents/BaseLight.xaml index 5aac023708..46767feca0 100644 --- a/src/Avalonia.Themes.Default/Accents/BaseLight.xaml +++ b/src/Avalonia.Themes.Default/Accents/BaseLight.xaml @@ -1,60 +1,56 @@ diff --git a/src/Avalonia.Themes.Default/CheckBox.xaml b/src/Avalonia.Themes.Default/CheckBox.xaml index 62a05a3525..3d14dd8e51 100644 --- a/src/Avalonia.Themes.Default/CheckBox.xaml +++ b/src/Avalonia.Themes.Default/CheckBox.xaml @@ -40,6 +40,9 @@ + @@ -58,4 +61,4 @@ - \ No newline at end of file + diff --git a/src/Avalonia.Themes.Default/TreeViewItem.xaml b/src/Avalonia.Themes.Default/TreeViewItem.xaml index ada86d3535..b5e0e7a005 100644 --- a/src/Avalonia.Themes.Default/TreeViewItem.xaml +++ b/src/Avalonia.Themes.Default/TreeViewItem.xaml @@ -1,92 +1,92 @@ - + - + - + - + - + - + - + - + - + - +