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

Xaml onVisibilityChanged do something

I have element with visibility but I don’t know to do something on isVisibleChanged right way.

So lets say I have element with name SomePanel
So I can access SomePanel.IsVisibleChanged

What I found on the internet is

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

public event DependencyPropertyChangedEventHandler IsSomePanelVisible;
somePanel.IsVisibleChanged += IsSomePanelVisible;

But I need method after += where can I put my logic. How can I do that?

>Solution :

First you have to create the method that will be called :

 private void VisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
    {

    }

Then add the handler :

somePanel.IsVisibleChanged += VisibleChanged;

The method can be later in the code, it doesn’t matter.

EDIT :

Like Shemberle said, you can also do it from the XAML like this : (expecting that you keep "VisibleChanged" as your method name)

<Panel IsVisibleChanged="VisibleChanged" />

The interesting point to note is that adding it in the XAML creates the "link" between the event and the method from the beginning whereas adding it programatically only creates the link at the moment of your choice.
Conversely, you can remove the link in the same way, just change + by :

somePanel.IsVisibleChanged -= VisibleChanged;
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