【WPF】 TabControl的TabItem平分寬度


如圖所示:

 

要做到這種效果,可以對TabControl的Style進行重寫,上代碼:

 1  <Style x:Key="TabControlStyle" TargetType="{x:Type TabControl}">
 2         <Setter Property="Template">
 3             <Setter.Value>
 4                 <ControlTemplate TargetType="{x:Type TabControl}">
 5                     <Grid Background="Transparent">
 6                         <Grid.RowDefinitions>
 7                             <RowDefinition Height="Auto"/>
 8                             <RowDefinition Height="*"/>
 9                         </Grid.RowDefinitions>
10                         <Border  BorderBrush="Transparent" BorderThickness="0 0 0 0">
11                             <!--<TabPanel IsItemsHost="True"/>-->
12                             <UniformGrid Rows="1" IsItemsHost="True"></UniformGrid>
13                         </Border>
14                         <Border Grid.Row="1"
15                                     BorderBrush="Transparent"
16                                     Padding="0"
17                                     BorderThickness="0" Background="{TemplateBinding Background}">
18                             <ContentPresenter ContentSource="SelectedContent" Name="PART_SelectedContentHost"/>
19                         </Border>
20                     </Grid>
21 
22                 </ControlTemplate>
23             </Setter.Value>
24         </Setter>
25     </Style>

Border 標簽中,將TabPanel換為UniformGrid,要注意的一點是:這個Rows="1",必須設置。

 

感謝您的閱讀。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM