Set binding programatically

Dec 17, 2010 at 8:48 PM

Hi!

 

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.

Coordinator
Dec 17, 2010 at 8: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.