制作的TabControl头滚动在WPF [英] Make TabControl Headers Scrollable in WPF
本文介绍了制作的TabControl头滚动在WPF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
正如标题所说,我想改变我的TabControl的标题是滚动
原因:我有太多的的TabItems,该包装是不是在我的情况下,最好的解决方案。所以我想从改变:
要类似的东西(由箭头指示的滚动条):
谁能帮我展示了如何做到这一点? (我使用WPF)
解决方案
修改 TabControl.Template
来一些简单的像,这似乎为我工作
<预类=郎咸平的XML prettyprint-覆盖>
< TabControl的...>
< TabControl.Template>
<的ControlTemplate的TargetType ={X:类型的TabControl}>
<网格和GT;
< Grid.RowDefinitions>
< RowDefinition高度=自动/>
< RowDefinition />
< /Grid.RowDefinitions>
<的ScrollViewer HorizontalScrollBarVisibility =自动VerticalScrollBarVisibility =已禁用>
<的TabPanel X:NAME =HeaderPanelIsItemsHost =真保证金=0,4,0,0/>
< /&的ScrollViewer GT;
< ContentPresenter X:NAME =PART_SelectedContentHost保证金=4ContentSource =SelectedContentGrid.Row =1/>
< /网格和GT;
< /控件模板>
< /TabControl.Template>
< / TabControl的>
As Mentioned in Title, I want to change the header of my TabControl to be scrollable.
The reason: I have too many tabItems, and the wrapping is not the best solution in my case. so I want to change it from :
To something like that (Scroll bar indicated by the arrow) :
Can anyone help me and show how to do that ? (I'm using wpf)
解决方案
Changing TabControl.Template
to something simple like this seems to work for me
<TabControl ...>
<TabControl.Template>
<ControlTemplate TargetType="{x:Type TabControl}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Disabled">
<TabPanel x:Name="HeaderPanel" IsItemsHost="True" Margin="0,4,0,0"/>
</ScrollViewer>
<ContentPresenter x:Name="PART_SelectedContentHost" Margin="4" ContentSource="SelectedContent" Grid.Row="1"/>
</Grid>
</ControlTemplate>
</TabControl.Template>
</TabControl>
这篇关于制作的TabControl头滚动在WPF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文