WPF How to change image visibility from another Window
How to cha开发者_如何学JAVAnge image visibility from another Window`s button click event in WPF C#?
Any of the thousand possible ways. The simplest would be:
partial class Window2 : Window
{
...
private Window1 _otherWindow;
private void OnClick(object sender, RoutedEventArgs e)
{
_otherWindow.image.Visibility = Visibility.Collapsed;
}
}
A better way would be to bind the image visibility to the ViewModel's property, and change that property in the click handler.
Or you can associate a command with the button, and change the ViewModel of the window containing the image as a part of the business logic.
Etc. etc. etc.
Create a public property in the class called ImageVisible
that exposes the image's visible property. Then you can can just set it to true or false depending on weather you want it visible or not.
精彩评论