我如何添加额外的内容到一个WPF TabControl的? [英] How can I add extra content to a WPF TabControl?

查看:2461
本文介绍了我如何添加额外的内容到一个WPF TabControl的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WPF TabControl的一个自定义的ControlTemplate,增加了按键的TabItem的头部的左侧和右侧。目前,这不是作为按钮命令在CONTROLTEMPLATES XAML约束,不需要的ControlTemplate以外的地方露出了一个名为一部分。



这工作正常一个按钮,但如果我想添加可在控件模板之外,使我的TabControl变得更加灵活?

$的约束TabItemHeaders的的内容的左侧(或右侧),右手边是什么b
$ b

我的想法是子类的TabControl,并有在ControlTemplate中两个命名的部分和揭露这些作为新控件的属性;的 CustomTabControl.LeftContentArea分别为的和的 CustomTabControl.RightContentArea 的。每个命名的部分是一个ContentPresenter,每个ContentPresenters内​​容属性是由上面提到的属性公开。



然而,当我尝试这样做我无法把内容放到左边, 。正确的内容领域



编辑:只是要清楚我已经包括图像。红色矩形显示,我希望能够把额外的内容。



替换文本



更新:下面是我迄今所取得的进展的屏幕截图,希望这将有助于解释我的问题多一点。



的屏幕截图显示我的自定义选项卡控件有两个空白标签和三个按钮,目前在 TabItem的的标题区域的右侧。该按钮在的TabControls 的自定义的控件模板的I.E.当前定义还有的 ColumnDefinition 的内部的 CONTROLTEMPLATES 的网格,其中包含一个的的StackPanel 的承载3个按键。





我在找的是一个方式,让标签控件的消费者决定哪些内容进入的区域旁边的标签。例如。用户应该能够做这样的事:

 <局部:CustomTabControl> 
<局部:CustomTabControl.RightContentArea>
将;! - 这是可以改变的,以用户想要的任何内容 - >
< StackPanel的方向=横向>
<按钮内容=测试/>
<按钮内容=测试/>
<按钮内容=测试/>
< / StackPanel的>
< /地方:CustomTabControl.RightContentArea>

<! - 的TabItems被添加为正常 - >
< TabItem的标题=选项卡一号/>
< TabItem的标题=标签两个/>

< /地方:CustomTabControl>


解决方案

对于任何人谁是有兴趣的this 计算器后回答我的问题完全


I have a custom ControlTemplate for a WPF TabControl that adds Buttons to the left and right hand side of the TabItem header. At the moment this is not a named part as the button commands are bound in the ControlTemplates XAML and do not need to be exposed outside of the ControlTemplate.

This works fine for a button but what if I want to add content to the left (or right) hand side of the TabItemHeaders which can be bound outside of the ControlTemplate so that my TabControl becomes more flexible?

My idea was to subclass the TabControl and have two named parts in the ControlTemplate and expose these as properties of the new control; CustomTabControl.LeftContentArea and CustomTabControl.RightContentArea respectively. Each named part is a ContentPresenter and each ContentPresenters Content property is exposed by the properties named above.

However, when I tried this I was unable to put content into the left and right content areas.

Edit: Just to be clear I have included an image. The red rectangles show where I want to be able to place extra content.

Update: Below is a screen shot of the progress I have made so far, hopefully this will help explain my problem a bit more.

The screen shot shows my custom Tab Control with two blank tabs and three buttons that are currently on the right hand side of the TabItem header area. The buttons are currently defined in the TabControls custom ControlTemplate I.E. there is a ColumnDefinition within the ControlTemplates Grid which contains a StackPanel that hosts 3 buttons.

What I am looking for is a way to allow the consumer of the tab control decide what content goes in the area next to the tabs. E.G. the user should be able to do something like this:

<local:CustomTabControl>
    <local:CustomTabControl.RightContentArea>
        <!-- This can be changed to ANY content that the user wants -->
        <StackPanel Orientation="Horizontal">
            <Button Content="Test" />
            <Button Content="Test" />
            <Button Content="Test" />
        </StackPanel>
    </local:CustomTabControl.RightContentArea>

    <!-- TabItems are added as normal -->
    <TabItem Header="Tab One" />
    <TabItem Header="Tab Two" />

</local:CustomTabControl>

解决方案

For anyone who's interested this stackoverflow post answers my question perfectly.

这篇关于我如何添加额外的内容到一个WPF TabControl的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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