Reputation: 1745
When I initialize a control property from code, the binding to the same property defined on XAML don't work. Why?
For Example, I set control properties on startup with this statements:
myControl.SetValue(UIElement.VisibilityProperty, DefaultProp.Visibility);
myControl.SetValue(UIElement.IsEnabledProperty, DefaultProp.IsEnabled);
and on xaml I bind the property of myControl in this way:
IsEnabled="{Binding Path=IsKeyControlEnabled}"
now, when the property "IsKeyControlEnabled" changes to false, myControl remains enabled (because it's initialize with true value).
How can I do?
Upvotes: 2
Views: 1482
Reputation: 32639
This is the proper behavior - it is by design. Explicitly assigned values override values obtained through data bindings. WPF bindings remove the need to explicitly reference UI objects and their properties. To set the value of the property simply change the value it is binded to - in your case:
IsKeyControlEnabled = DefaultProp.IsEnabled;
Upvotes: 3