Alex Rivera | Logout

How to programmatically bind Visibility on a button to INotifyPropertyChanged boolean property in C#?

Asked 2011-08-24T19:45:56.233
9

Here's what I got to so far:

System.Windows.Data.Binding binding = new System.Windows.Data.Binding("MyProperty");
binding.Mode = System.Windows.Data.BindingMode.TwoWay;
binding.Converter = new System.Windows.Controls.BooleanToVisibilityConverter(); 
binding.Source = mySourceObject;

this.SetBinding(this.myButton.Visibility, binding);

but visibility is not a dependency property, so how can I do this?

Edit
Report

1 Answer

7

You need to pass in the static Visibility dependency property itself (which Button inherits from UIElement), not the value of the property on the button instance, e.g.:

myButton.SetBinding(UIElement.VisibilityProperty, binding);
answered 2011-08-24T19:53:12.677

Your Answer