Search code examples
c#wpfxamlvisibilityuielement

UIElement's Visibility control from different UIElement


I have two UIElements X (X.xaml, Name="_X") and Y (Y.xaml, Name="_Y"). How can I control Visibility of Y.xaml from X.xaml.cs?

It's easy to control Visibility of Y.xaml from Y.xaml.cs, as I can use _Y.Visibility = SOMETHING, but I don't know how to do that from X.xaml.cs.


Solution

  • This is a common programming question about accessing the properties/members of one class from within another.

    You need to grab a hold of a reference to the instance of the class you're trying to access. That depends on how they are created and how they related to each other in terms of object graph. Do they share the same parent, etc?