Overriding default ItemsPanelTemplate in Silverlight 4?

1k views Asked by At

I am trying to override the default template for TabControl in Silverlight. Instead of having the tabs wrap around when they are full, I want to make it so the user can scroll through them, similar to a ListBox. However, Silverlight just ignores everything I put in "ItemsPanelTemplate" and renders the default. Here is the relevant code:

    <swc:TabControl Grid.Row="0" Grid.Column="1" Name="Tabs">
        <swc:TabControl.ItemsPanel>
            <ItemsPanelTemplate>
                <ScrollViewer>
                     <StackPanel Orientation="Horizontal" />
                </ScrollViewer>
            </ItemsPanelTemplate>
        </swc:TabControl.ItemsPanel>

Even if I just put in a regular StackPanel, it still does nothing at all. I am using the Silverlight Toolkit for the tabs, so everything I find online is just for regular WPF and does not work for Silverlight. Thank you all very much for your advice.

1

There are 1 answers

1
CodeNaked On BEST ANSWER

The ItemsPanel needs to have a Panel in it as the root element. You have a ScrollViewer. If you want to add a ScrollViewer, you'd have to create a custom ControlTemplate that wraps the ItemsPresenter with a ScrollViewer. The ItemsPresenter will be where the ItemsPanel is shown.

You should be able to get the default Style and ControlTemplate from the Silverlight Toolkit source and tweak it to your needs. Then include your modified version in your application resources or apply it explicitly to individual TabControls.