Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

wpf

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?

like image 517
Shai UI Avatar asked Aug 24 '11 19:08

Shai UI


1 Answers

You should be able to do

Button.VisibilityProperty

instead of

this.myButton.Visibility

http://msdn.microsoft.com/en-us/library/system.windows.uielement.visibilityproperty.aspx

like image 191
Jeff Avatar answered Sep 18 '22 05:09

Jeff