I am trying to dynamically add tabs to a TabControl using code behind where the template used for HeaderTemplate includes bound controls. Everything is working as I expected, except I cannot get the bound data to appear on the tab.
This is my header template:
And this is my TabControl declaration:
Here is my code behind for adding a new tab to the TabControl:
And here is a stripped down version of the object I am trying to bind:
I have tried setting the DataContext of the tab item (as shown), the tab control, and the window itself without any change. Changing the order in which the item's properties are set also had no affect. I know the tempate is being used because if I change the binding to static text, the text is displayed on the tab correctly. What am I missing here?
This is my header template:
<Application.Resources> |
<DataTemplate x:Key="TabItemHeaderTemplate"> |
<StackPanel Orientation="Horizontal" IsHitTestVisible="False"> |
<TextBlock Name="tbTabCaption" Foreground="Black" Margin="3,0,0,0" Text="{Binding Path=ConfigModel}"/> |
</StackPanel> |
</DataTemplate> |
</Application.Resources> |
And this is my TabControl declaration:
<StackPanel Grid.Row="1" Grid.ColumnSpan="2" Orientation="Vertical" > |
<TextBlock Margin="5" FontWeight="Bold" Text="Select a product configuration"></TextBlock> |
<telerikNavigation:RadTabControl x:Name="tabControl" Margin="2" SelectionChanged="tabControl_SelectionChanged" TabStripPlacement="Left" VerticalAlignment="Top" HorizontalAlignment="Left"> |
</telerikNavigation:RadTabControl> |
</StackPanel> |
Here is my code behind for adding a new tab to the TabControl:
CProductConfiguration myObject = new CProductConfiguration(); |
RadTabItem newTabItem = new RadTabItem() |
{ |
DataContext = myObject, |
HeaderTemplate = (DataTemplate)Application.Current.Resources["TabItemHeaderTemplate"], |
Margin = new Thickness(2), |
MinHeight=50, |
MinWidth=100 |
}; |
tabControl.Items.Add(newTabItem); |
And here is a stripped down version of the object I am trying to bind:
public interface IProductConfiguration |
{ |
string ConfigModel { get; } |
} |
class CProductConfiguration : IProductConfiguration |
{ |
public string ConfigModel |
{ |
get { return "MyModel"; } |
} |
} |
I have tried setting the DataContext of the tab item (as shown), the tab control, and the window itself without any change. Changing the order in which the item's properties are set also had no affect. I know the tempate is being used because if I change the binding to static text, the text is displayed on the tab correctly. What am I missing here?