开发者

Overriding default ItemsPanelTemplate in Silverlight 4?

I am trying to override the default template for TabControl in Silverlight. Instead of having the tabs wrap ar开发者_Python百科ound 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜