且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Silverlight 4:制作可关闭的Tabitems

更新时间:2023-12-06 17:32:46

您可以使用Template TabItem拥有某种关闭按钮,您可以将其连接到后面的代码中以关闭当前选定的选项卡.

You can Template TabItem to have some sort of close button that you can hook up in code behind to close the currently selected tab.

<Style TargetType="TabItem">
            <Setter.Value>
                <ControlTemplate TargetType="sdk:TabItem">
                            <Button x:Name="PART_btnClose"
                                            Height="15"
                                            Width="15"
                                            Grid.Column="1"
                                            HorizontalAlignment="Right"
                                            VerticalAlignment="Center"
                                            Margin="20,0,3,8" BorderThickness="1" Cursor="Hand" />
</ControlTemplate>
</Setter.Value>
</Style>

在此之后,您可以在应用模板中订阅ButtonClicked事件.

After this, in on apply template you can subscribe to the ButtonClicked Event.

类似这样的东西:

public override void OnApplyTemplate()
    {
        base.OnApplyTemplate();

        PART_btnClose = GetTemplateChild("PART_btnClose") as Button;

        if (PART_btnClose != null)
        {
            PART_btnClose.Click += new RoutedEventHandler(PART_btnClose_Click);
        }

在这种情况下,您可以关闭标签页.

In that event, you can close your tab.

希望这会有所帮助,代码可能无法按原样工作,只是很快就完成了.

Hope This helps, code might not work as is, just did it quickly.

Ty Rozak