Irakli Lekishvili
Irakli Lekishvili

Reputation: 34158

WPF How to change image visibility from another Window

How to change image visibility from another Window`s button click event in WPF C#?

Upvotes: 1

Views: 4466

Answers (2)

Vlad
Vlad

Reputation: 35584

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.

Upvotes: 2

Icemanind
Icemanind

Reputation: 48686

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.

Upvotes: 1

Related Questions