Following this How To I'm trying to add close buttons to my tab headers.
The "Style" I'm using is exactly as in the example above, but located in a seperate xaml named "TabStyles".
I have a UserControl "TabControl" with a grid containing my Telerik RadTabControl named "MyTabControl".
In the code behind of the UserControl I do this:
public TabControl()
{
InitializeComponent();
TabStyles s = new TabStyles();
Style s1 = (Style)s.Resources["ClosableStyle"];
MyTabControl.ItemContainerStyle = s1;
}
I add my tab items programmatically like for example below:
public void InitializeTabControl(IEnumerable<XElement> data, int startValue, bool readOnly)
{
_readOnly = readOnly;
ParseXMLData(data, startValue);
foreach (LIT item in TDetailsList)
{
var t = new RadTabItem();
InitializeTabItem(t,item);
MyTabControl.Items.Add(t);
}
if(MyTabControl.Items.Count <=0 )
{
var t = new RadTabItem();
InitializeTabItem(t,
new LIT());
MyTabControl.Items.Add(t);
}
if(!_readOnly)
AddEmptyTab();
}
The "ClosableStyle" does not take any effect. Do I have to work with ObservableCollections?
After having set the style of the "MyTabControl" I can see that I have the following exception in the ItemContainerStyle.TargetType.DeclaringMethod:
DeclaringMethod = '((System.RuntimeType)((Telerik.Windows.Controls.ItemsControl)(TermsTabControl)).ItemContainerStyle.TargetType).DeclaringMethod' threw an exception of type 'System.InvalidOperationException'
Regards,
Niclas