user3669879
user3669879

Reputation: 37

C# WPF - Toggle visibility of something isn't working

Like button.IsVisible = false isn't working... It gives error:

Property or indexer 'System.Windows.UIElement.IsVisible' cannot be assigned to -- it is read only

I'm making a WPF application...

Upvotes: 1

Views: 2752

Answers (1)

BradleyDotNET
BradleyDotNET

Reputation: 61379

You don't use IsVisible in WPF, you set the Visibility property:

button.Visibility = Visibility.Collapsed;

Or, to make it visible:

button.Visibility = Visibility.Visible;

Technically, there is also Visibility.Hidden which doesn't remove it from the layout. This isn't used very often, and is one of the "Know what you are doing before using" kind of options.

Upvotes: 5

Related Questions