在Silverlight中拉伸TabItem标头

时间:2011-05-25 11:04:39

标签: silverlight xaml tabcontrol

如何使标签项标题在Silverlight中的标签控件的宽度上延伸?如果重要的话,我总是有一些固定数量的标签。

我在IMultiValueConverter here中找到了WPF示例。

1 个答案:

答案 0 :(得分:2)

这是一个例子

http://cid-a1de71e9f2ae2f82.office.live.com/self.aspx/.Public/ExtendedTabControl.zip

这是一个非常简单的任务..您所要做的就是创建默认模板的副本,并将System_Windows_Controls_Primitives:TabPanel x:Name="TabPanelTop"替换为基本覆盖布局逻辑的te:StockPanel x:Name="TabPanelTop"

public class StockPanel: System.Windows.Controls.Primitives.TabPanel
{
    protected override Size MeasureOverride(Size availableSize)
    {
        var cc = Children.Count;

        foreach (var child in Children)
        {
            child.Measure(new Size(availableSize.Width / cc, availableSize.Height));
        }

        return base.MeasureOverride(availableSize);
    }

    protected override Size ArrangeOverride(Size finalSize)
    {
        var cc = Children.Count;
        var i = 0;

        foreach (var child in Children)
        {
            child.Arrange(new Rect((finalSize.Width / cc) * i, 0, finalSize.Width / cc, finalSize.Height));
            i++;
        }

        return new Size(finalSize.Width, finalSize.Height);
    }
}

PS:这不是完美的代码示例,但我认为你很难理解如何扩展TabControl