if (span.Text == "Specific String")
{
var spanAncestor = span.Parent.Parent;
spanAncestor.IsVisible = false; // Throws error. Read below.
}
The error I get is:
Error CS1061 ‘Element’ does not contain a definition for ‘IsVisible’
and no accessible extension method ‘IsVisible’ accepting a first
argument of type ‘Element’ could be found (are you missing a using
directive or an assembly reference?)
The span has as a parent a FormattedString, which has as a parent a Label.
Is there a way to set IsVisible property for the ancestor element?
>Solution :
Parent is of type Element, which does not have an IsVisible property. You need to cast it first
if (parent is VisibleElement)
{
((VisibleElement)parent).IsVisible = false;
}