C# wpf - A xaml has these buttons:
In the xaml.cs code, to hide the gBuOk Button, this does not work:
this.gBuOk.Visibility = "Hidden";
How do I hide the gBuOk Button?
C# wpf - A xaml has these buttons:
In the xaml.cs code, to hide the gBuOk Button, this does not work:
this.gBuOk.Visibility = "Hidden";
How do I hide the gBuOk Button?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Naimish MakwanaPosted Mar 26, 2024, 7:10 AM
In WPF, the
Visibilityproperty is an enumeration, not a string. So you should useVisibility.Hiddeninstead of"Hidden". Here’s how you can do it:This will hide the
gBuOkbutton in your WPF application. If you want to make it visible again, you can use:Thanks
Tuhin PaulPosted Mar 26, 2024, 2:43 AM
This code sets the
Visibilityproperty of thegBuOkbutton toVisibility.Hidden. This will hide the button on the UI but still reserve the space it occupies in the layout. There's another option,Visibility.Collapsed, which not only hides the button but also collapses its allotted space in the layout, making other elements potentially resize.Visibility.Visible: This is the default value, and the button is shown on the UI.Visibility.Hidden: The button is hidden but still occupies space in the layout.Visibility.Collapsed: The button is hidden and its space collapses, potentially affecting the layout of other elements.Tuhin PaulPosted Mar 26, 2024, 2:43 AM
The issue with your code is that you're trying to assign a string value ("Hidden") to the
Visibilityproperty. Instead, you need to use the pre-definedVisibilityenumeration provided by WPF.