How to set Visibility Property thro Code in WPF

Aug 29, 2009 at 9:12 AM


I am new to WPF. I have created a button control in WPF and I want to show the button only when i trigger another event. In XAML for button Visible property I have set the value as "Hidden" and when I set btn.Visibility = "Visible" thro C# code, I am getting the following error

Cannot convert type 'string' to 'System.Windows.Visibility'

Please help me on this. Thanks

Aug 29, 2009 at 1:27 PM


You are trying to set the value as a string which is incorrect. 

You have to set it like this.

btn.Visibility = Visibility.Visible

no quotes around it.