选项卡标题旁边的 UIElements

发布于 2024-07-23 07:52:21 字数 270 浏览 11 评论 0原文

有没有办法将某些内容(自定义 UIElement)放置在 TabItem 标题的右侧,以便标题会考虑其大小。

我觉得应该有一个适合他们的数据模板,但我不知道该读什么或如何查询谷歌。

替代文本 http://trotsenko.com.ua/files/sample.png

Is there a way to place something (a custom UIElement) in place on the right of TabItems' headers, so that the headers will consider its size.

I feel like there should be a data template for them, but I do not know what to read or how to query google for that.

alt text http://trotsenko.com.ua/files/sample.png

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

尾戒 2024-07-30 07:52:21

没有一种简单的方法可以将内容放置在该位置,但有一种方法。 为此,您必须覆盖 TabControl 的默认 ControlTemplate

大多数系统主题将 TabPanel (选项卡所在的位置)和选项卡内容放在 Grid 中,如下所示:

<ControlTemplate TargetType="{x:Type TabControl}">
                    <Grid KeyboardNavigation.TabNavigation="Local"
                          SnapsToDevicePixels="true"
                          ClipToBounds="true">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition x:Name="ColumnDefinition0"/>
                            <ColumnDefinition x:Name="ColumnDefinition1"
                                              Width="Auto"/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition x:Name="RowDefinition0"
                                           Height="Auto"/>
                            <RowDefinition x:Name="RowDefinition1"
                                           Height="*"/>
                        </Grid.RowDefinitions>
                        <TabPanel x:Name="HeaderPanel"
                                  Panel.ZIndex ="1" 
                                  KeyboardNavigation.TabIndex="1"
                                  Grid.Column="0"
                                  Grid.Row="0"
                                  Margin="2,2,2,0"
                                  IsItemsHost="true"/>

                        <Border x:Name="ContentPanel"
                                BorderThickness="0,0,1,1"
                                BorderBrush="#D0CEBF"
                                KeyboardNavigation.TabNavigation="Local"
                                KeyboardNavigation.DirectionalNavigation="Contained"
                                KeyboardNavigation.TabIndex="2"
                                Grid.Column="0" Grid.ColumnSpan="2"
                                Grid.Row="1">
...

...

...
                        </Border>
                    </Grid>
...
                </ControlTemplate>

因此您可以添加另一个 ContentControl网格并将其绑定到自定义附加属性。 请记住,默认的 ControlTemplates 还具有许多控制溢出处理的触发器等,并且您必须确保其他 UI 元素不会干扰这些触发器。

不过,如果您不必处理 TabControl 方向或溢出,您应该能够很快获得类似的结果:

三个带有红色边框和 TextBlock 的 TabItem http://img35.imageshack.us/img35/3237/tabpanelexample.png

祝你好运!

There isn't an easy way to place content in that location, but there is a way. To do that you'll have to override the default ControlTemplate for TabControl.

Most system themes put the TabPanel (where the tabs are) and the tab contents in a Grid like so:

<ControlTemplate TargetType="{x:Type TabControl}">
                    <Grid KeyboardNavigation.TabNavigation="Local"
                          SnapsToDevicePixels="true"
                          ClipToBounds="true">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition x:Name="ColumnDefinition0"/>
                            <ColumnDefinition x:Name="ColumnDefinition1"
                                              Width="Auto"/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition x:Name="RowDefinition0"
                                           Height="Auto"/>
                            <RowDefinition x:Name="RowDefinition1"
                                           Height="*"/>
                        </Grid.RowDefinitions>
                        <TabPanel x:Name="HeaderPanel"
                                  Panel.ZIndex ="1" 
                                  KeyboardNavigation.TabIndex="1"
                                  Grid.Column="0"
                                  Grid.Row="0"
                                  Margin="2,2,2,0"
                                  IsItemsHost="true"/>

                        <Border x:Name="ContentPanel"
                                BorderThickness="0,0,1,1"
                                BorderBrush="#D0CEBF"
                                KeyboardNavigation.TabNavigation="Local"
                                KeyboardNavigation.DirectionalNavigation="Contained"
                                KeyboardNavigation.TabIndex="2"
                                Grid.Column="0" Grid.ColumnSpan="2"
                                Grid.Row="1">
...

...

...
                        </Border>
                    </Grid>
...
                </ControlTemplate>

So you could add another ContentControl to the grid and have it bind to a custom Attached Property. Keep in mind that the default ControlTemplates also have a lot of triggers which control overflow handling, amongst other things, and you'd have to make sure that your additional UI Elements don't interfere with that.

You should be able to get something like this fairly quickly, though, if you don't have to deal with TabControl orientation or overflow:

Three TabItems with a Red Border and TextBlock http://img35.imageshack.us/img35/3237/tabpanelexample.png

Good luck!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文