Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 1 addition & 56 deletions src/Controls/src/Core/VisualElement/VisualElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -269,12 +269,9 @@ static void OnTransformChanged(BindableObject bindable, object oldValue, object
BindableProperty.Create("TransformOrigin", typeof(Point), typeof(VisualElement), new Point(.5d, .5d),
propertyChanged: (b, o, n) => { (((VisualElement)b).AnchorX, ((VisualElement)b).AnchorY) = (Point)n; });

bool _isVisibleExplicit = (bool)IsVisibleProperty.DefaultValue;

/// <summary>Bindable property for <see cref="IsVisible"/>.</summary>
public static readonly BindableProperty IsVisibleProperty = BindableProperty.Create(nameof(IsVisible), typeof(bool), typeof(VisualElement), true,
propertyChanged: (bindable, oldvalue, newvalue) => ((VisualElement)bindable).OnIsVisibleChanged((bool)oldvalue, (bool)newvalue),
coerceValue: CoerceIsVisibleProperty);
propertyChanged: (bindable, oldvalue, newvalue) => ((VisualElement)bindable).OnIsVisibleChanged((bool)oldvalue, (bool)newvalue));

/// <summary>Bindable property for <see cref="Opacity"/>.</summary>
public static readonly BindableProperty OpacityProperty = BindableProperty.Create(nameof(Opacity), typeof(double), typeof(VisualElement), 1d, coerceValue: (bindable, value) => ((double)value).Clamp(0, 1));
Expand Down Expand Up @@ -697,36 +694,6 @@ private protected bool InputTransparentCore
}
}

/// <summary>
/// This value represents the cumulative IsVisible value.
/// All types that override this property need to also invoke
/// the RefreshIsVisibleProperty() method if the value will change.
/// </summary>
private protected bool IsVisibleCore
{
get
{
if (_isVisibleExplicit == false)
{
// If the explicitly set value is false, then nothing else matters
// And we can save the effort of a Parent check
return false;
}

var parent = Parent as VisualElement;
while (parent is not null)
{
if (!parent.IsVisible)
{
return false;
}
parent = parent.Parent as VisualElement;
}

return _isVisibleExplicit;
}
}

/// <summary>
/// Gets a value indicating whether this element is focused currently. This is a bindable property.
/// </summary>
Expand Down Expand Up @@ -1532,7 +1499,6 @@ internal virtual void OnIsVisibleChanged(bool oldValue, bool newValue)
fe.Handler?.UpdateValue(nameof(IView.Visibility));
}

(this as IPropertyPropagationController)?.PropagatePropertyChanged(IsVisibleProperty.PropertyName);
InvalidateMeasureInternal(InvalidationTrigger.Undefined);
}

Expand Down Expand Up @@ -1697,17 +1663,6 @@ static object CoerceInputTransparentProperty(BindableObject bindable, object val
return false;
}

static object CoerceIsVisibleProperty(BindableObject bindable, object value)
{
if (bindable is VisualElement visualElement)
{
visualElement._isVisibleExplicit = (bool)value;
return visualElement.IsVisibleCore;
}

return false;
}

static void OnInputTransparentPropertyChanged(BindableObject bindable, object oldValue, object newValue)
{
(bindable as IPropertyPropagationController)?.PropagatePropertyChanged(VisualElement.InputTransparentProperty.PropertyName);
Expand Down Expand Up @@ -1775,9 +1730,6 @@ void IPropertyPropagationController.PropagatePropertyChanged(string propertyName
if (propertyName == null || propertyName == InputTransparentProperty.PropertyName)
this.RefreshPropertyValue(InputTransparentProperty, _inputTransparentExplicit);

if (propertyName == null || propertyName == IsVisibleProperty.PropertyName)
this.RefreshPropertyValue(IsVisibleProperty, _isVisibleExplicit);

PropertyPropagationExtensions.PropagatePropertyChanged(propertyName, this, ((IVisualTreeElement)this).GetVisualChildren());
}

Expand All @@ -1788,13 +1740,6 @@ void IPropertyPropagationController.PropagatePropertyChanged(string propertyName
protected void RefreshIsEnabledProperty() =>
this.RefreshPropertyValue(IsEnabledProperty, _isEnabledExplicit);

/// <summary>
/// This method must always be called if some event occurs and the value of
/// the <see cref="IsVisibleCore"/> property will change.
/// </summary>
internal void RefreshIsVisibleProperty() =>
this.RefreshPropertyValue(IsVisibleProperty, _isVisibleExplicit);

/// <summary>
/// This method must always be called if some event occurs and the value of
/// the InputTransparentCore property will change.
Expand Down
74 changes: 0 additions & 74 deletions src/Controls/tests/Core.UnitTests/VisualElementTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -317,79 +317,5 @@ public void WidthAndHeightRequestPropagateToHandler()
Assert.Equal(2, heightMapperCalled);
Assert.Equal(2, widthMapperCalled);
}

[Fact]
public void ShouldPropagateVisibilityToChildren()
{
var grid = new Grid() { IsVisible = false };
var label = new Label() { IsVisible = true };
grid.Add(label);

Assert.False(label.IsVisible);
Assert.Equal(grid.IsVisible, label.IsVisible);
}

[Theory]
[InlineData(false, true, true, false, false, false)]
[InlineData(true, false, true, true, false, false)]
public void IsVisiblePropagates(bool rootIsVisible, bool nestedIsVisible, bool childIsVisible, bool expectedRootVisibility, bool expectedNestedVisibility, bool expectedChildVisibility)
{
var root = new Grid() { IsVisible = rootIsVisible };
var nested = new Grid() { IsVisible = nestedIsVisible };
var child = new Button() { IsVisible = childIsVisible };

nested.Add(child);
root.Add(nested);

Assert.Equal(root.IsVisible, expectedRootVisibility);
Assert.Equal(nested.IsVisible, expectedNestedVisibility);
Assert.Equal(child.IsVisible, expectedChildVisibility);
}

[Fact]
public void IsVisibleParentCorrectlyUnsetsPropagatedChange()
{
var button = new Button();
var grid = new Grid { button };

grid.IsVisible = false;
Assert.False(button.IsVisible);

grid.IsVisible = true;
Assert.True(button.IsVisible);
}

[Fact]
public void ButtonShouldStayHiddenIfExplicitlySet()
{
var button = new Button { IsVisible = false };
var grid = new Grid { button };

grid.IsVisible = false;
Assert.False(button.IsVisible);

// button stays hidden if it was explicitly set
grid.IsVisible = true;
Assert.False(button.IsVisible);
}

[Fact]
public void ButtonShouldBeVisibleWhenExplicitlySetWhenParentIsVisible()
{
var button = new Button { IsVisible = false };
var grid = new Grid { button };

// everything is hidden
grid.IsVisible = false;
Assert.False(button.IsVisible);

// make button visible, but it should not appear
button.IsVisible = true;
Assert.False(button.IsVisible);

// button appears when parent appears
grid.IsVisible = true;
Assert.True(button.IsVisible);
}
}
}
3 changes: 3 additions & 0 deletions src/Controls/tests/Xaml.UnitTests/Issues/Issue1549.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ public void ResourcesInNonXFBaseClassesAreFound()

Assert.AreEqual(true, label00.IsVisible);
Assert.AreEqual(false, label01.IsVisible);

Assert.AreEqual(4, InvertBoolenConverter.count);

}
}

Expand Down