Silverlight 4:制作可关闭的Tabitems [英] Silverlight 4 : Making Closeable Tabitems

查看:107
本文介绍了Silverlight 4:制作可关闭的Tabitems的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将选项卡控件扩展为具有可关闭的选项卡项.

I would like to extend the tab control to have closeable tab items.

我找到了Kent的WPF解决方案: 在WPF TabControl上-可以我要在标签标题旁边添加内容吗?

I have found this WPF solution of Kent: On the WPF TabControl - can I add content next to the tab headers?

我在Blend中打开了一个现有的silverlight tab控件的副本.但是,该结构看起来与WPF tabcontrol完全不同.我无法将其正确导入Silverlight控件模板.

I opened a copy of the existing silverlight tabcontrol in Blend. However the structure looks quite different to the WPF tabcontrol. I can't get it right into the Silverlight control template.

有人知道我的好资源吗?

Does anyone know a good resource for me?

推荐答案

您可以使用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

这篇关于Silverlight 4:制作可关闭的Tabitems的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆