When I create a new TabItem I create a new CheckBox at the same time.
I would like to bind the TabItem's visibility to the CheckBox, but am having trouble setting up the binding.
CheckBox cb = new CheckBox();
cb.Content = tabItemName;
cb.Name = tabItemName;
var visibilityBinding = new Binding("IsChecked");
visibilityBinding.Mode = BindingMode.TwoWay;
visibilityBinding.ElementName = cb.Name; // this could just be a string literal
visibilityBinding.Converter = new VisibilityConverter();
m.TabItem.SetBinding(TabItem.VisibilityProperty, visibilityBinding);
cb.IsChecked = true;
At runtime I get this error:
System.Windows.Data Error: BindingExpression path error: 'IsChecked' property not found on 'Telerik.Windows.Controls.RadTabItem' 'Telerik.Windows.Controls.RadTabItem' (HashCode=66442352). BindingExpression: Path='IsChecked' DataItem='Telerik.Windows.Controls.RadTabItem' (HashCode=66442352); target element is 'Telerik.Windows.Controls.RadTabItem' (Name='Central ...'); target property is 'Visibility' (type 'System.Windows.Visibility')..
What am I doing wrong? I thought the argument to the Binding ctor was the property on the source object (the CheckBox) that being bound to the property named in the SetBinding() call..
Thanks for any advice...
UPDATE:
I added
visibilityBinding.Source = cb;
and get this error at runtime:
Binding.RelativeSource cannot be set while using Binding.Source