这是我到目前为止所得到的:
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);
但是可见性不是依赖属性,所以我该怎么做呢?
答案 0 :(得分:11)
你应该能够做到
Button.VisibilityProperty
而不是
this.myButton.Visibility
http://msdn.microsoft.com/en-us/library/system.windows.uielement.visibilityproperty.aspx
答案 1 :(得分:6)
您需要传入静态Visibility依赖项属性本身(Button
继承自UIElement
),而不是按钮实例上的属性值,例如:
myButton.SetBinding(UIElement.VisibilityProperty, binding);