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

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

问题描述

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

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 tabcontrol 的副本.然而,结构看起来与 WPF 选项卡控件完全不同.我无法将其直接放入 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?

推荐答案

您可以通过模板 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.

泰罗扎克

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

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