Set binding programatically

Dec 17, 2010 at 9:48 PM



How can I set programatically the binding to a property. I have an tabItem (created dynamically) and I want to set the binding to its "IsEnabled" property in code. I have the boolean property already in the viewModel. I know I have to use SetAttach method (from Message class), but I am not sure what how the second param must be structured. Thanks.


var new tab = new TabItem();

Message.SetAttach(newTab, "What should be here");

// bool property in viewModel -> IsOtherEnabled.

Dec 17, 2010 at 9:59 PM

If you are just trying to set a regular binding, you would do something like this:

var binding = new Binding("IsOtherEnabled");

tab.SetBinding(TabItem.IsEnabledProperty, binding);


Message.SetAttach is for attaching Actions.