SL tabControl Bind

Jan 21, 2011 at 8:01 PM

Hi, I'm trying to implement the MDI example in Silverlight but I don't know how to bind the TabItem element to the ViewModel to create the tabs related to a specific view. The control I'm using is the located in the reference xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk". Could please show me an code example implementing this?

The syntax of the TabControl is:

<sdk:TabControl Height="400" HorizontalAlignment="Center" Margin="65,63,75,0" Name="tabControl1" VerticalAlignment="Top" Width="500">
            <sdk:TabItem Header="tabItem1" Name="tabItem1" >
                <Grid />
            </sdk:TabItem>            
</sdk:TabControl>

Coordinator
Jan 21, 2011 at 8:12 PM
Edited Jan 21, 2011 at 8:12 PM

You can't databind the tab collection. Tab control is broken in Silverlight. There are issues for this in the Silverlight Toolkit. Please go vote for them so that the Silverlight Team will fix it. As a work around, I typically use a horizontal ListBox for the tabs and a ContentControl for the tab content.

You can databind hardcoded tabs. You would do something like this:

<sdk:TabControl Height="400" HorizontalAlignment="Center" Margin="65,63,75,0" Name="tabControl1" VerticalAlignment="Top" Width="500">
            <sdk:TabItem Header="tabItem1" Name="tabItem1" cal:Bind.Model="{Binding MyTabViewModel}" >
                <Grid />
            </sdk:TabItem>            
</sdk:TabControl>