-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Track IsEffectivelyVisible state #13972
Conversation
You can test this PR using the following package version. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some method names seem to be wrong: UpdateIsEffectivelyEnabled
, SyncIsEffectivelyEnabledFromParent
, it should be Visible
, not Enabled
.
Also, I may be reading it wrong, but not sure if the logic always works, e.g. does adding this to the test work?
child2.IsVisible = false;
root.IsVisible = true;
Assert.False(child2.IsEffectivelyEnabled);
Finally, I think there's room for optimization in UpdateIsEffectivelyEnabled
, so that it only needs to do the recursive call when child.IsVisible
.
@jp2masa thanks for the advise!
Good catch on this one! I'm adding this to the test now!
Makes sense |
You can test this PR using the following package version. |
We could simplify the code this way by avoiding loops. /// <summary>
/// Gets a value indicating whether this control and all its parents are visible.
/// </summary>
public bool IsEffectivelyVisible =>
IsVisible && (VisualParent?.IsEffectivelyVisible ?? true); |
@workgroupengineering we intend to provide internal change notifications when IEV changes, so we can't do what you suggested there unfortunately. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few nits, but also this doesn't seem to handle correctly setting the IsEffectivelyVisible
state when adding a grandchild. Here is a failing test:
[Fact]
public void Added_Grandchild_Has_Correct_IsEffectivelyVisible()
{
var child = new Decorator();
var grandchild = new Decorator();
var root = new TestRoot
{
IsVisible = false,
Child = child
};
child.Child = grandchild;
Assert.False(grandchild.IsEffectivelyVisible);
}
One failing.
- Pass the parent state to `UpdateIsEffectivelyVisible` - Remove some unneeded methods - Update `IsEffectivelyVisible` before calling visual tree attach/detach events.
The |
Previously,
IsEffectivelyVisible
was being calculated each time it was called. This was problematic for a couple of reasons:IsEffectivelyVisible
This PR changes
IsEffectivelyVisible
to be tracked likeIsEffectivelyEnabled
which fixes 1). It doesn't add a way to trackIsEffectivelyVisible
changes yet though so doesn't address 2).Regarding 2), making a
IsEffectivelyVisible
aDirectProperty
may be problematic for performance reasons as the change notifications need to be fired even if there are no listeners. A CLR event may be acceptable, but the main reason we need to track changes to this is internally for the animation system (PR to follow which hooks into this) so there are currently no plans to expose an API for detecting changes to this.