C# wpf - A xaml has these buttons:
C#
In the xaml.cs code, to hide the gBuOk Button, this does not work:
C#
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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Naimish MakwanaRank #324 · 7.7K reputationPosted Mar 26, 2024, 3:10 AM EDT
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.gBuOk.Visibility = System.Windows.Visibility.Hidden;This will hide the
gBuOkbutton in your WPF application. If you want to make it visible again, you can use:this.gBuOk.Visibility = System.Windows.Visibility.Visible;Thanks
Tuhin PaulRank #7 · 71.9K reputationPosted Mar 25, 2024, 10:43 PM EDT
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.Tuhin PaulRank #7 · 71.9K reputationPosted Mar 25, 2024, 10:43 PM EDT
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.