Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Accessing IsVisible property of a XAML element's parent in code-behind

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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;
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading