2011-03-23 102 views
7

我有一個WPF TabControl,帶有一些TabItems。如果有意義的話,我想在TabItems組的左邊和右邊留有邊距。WPF Tab頁邊距

我打算在下面畫一些ASCII藝術來表達觀點。我想要在第一個標籤左邊的固定邊距,但我也想在第三個標籤右邊有一個固定邊距。

|--------------------------------------------------| 
|   |-----||-----||-----|     | 
| <-Margin-> | 1 || 2 || 3 | <-Margin->  | 
|------------|  ||-----||-----|-----------------| 
|             | 
| How do I get margin or padding on both   | 
| sides of my tabs?        | 
|             | 
|             | 
|--------------------------------------------------| 

選項卡的數量是無限的,所以它們會隨着更多的添加而堆疊。它需要爲此正確工作。

此外,請注意,我不想讓整個選項卡控件變小。只是tabitem選項卡或標題或任何他們是。

我發現,如果我將標籤設置爲「60,0,-60,0」之類的邊距,我會在標籤左側獲得所需的效果,但這看起來像是黑客,而且將不適用於右手邊。

我在VS 2010中使用WPF 4.0。

乾杯!

回答

4

請嘗試使用此款式。

<Style TargetType="{x:Type TabControl}"> 
      <Setter Property="Template"> 
       <Setter.Value> 
        <ControlTemplate TargetType="{x:Type TabControl}"> 
         <Grid> 
          <Grid.RowDefinitions> 
           <RowDefinition Height="Auto"/> 
           <RowDefinition Height="*"/> 
          </Grid.RowDefinitions> 
          <TabPanel 
      Grid.Row="0" 
      Panel.ZIndex="1" 
      Margin="60,0,60,-1" 
      IsItemsHost="True" 
      Background="Transparent" /> 
          <Border 
      Grid.Row="1" 
      BorderBrush="Black" 
      BorderThickness="1" 
      CornerRadius="0, 12, 12, 12" > 
           <Border.Background> 
            <LinearGradientBrush> 
             <GradientStop Color="LightBlue" Offset="0" /> 
             <GradientStop Color="White" Offset="1" /> 
            </LinearGradientBrush> 
           </Border.Background> 
           <ContentPresenter ContentSource="SelectedContent" /> 
          </Border> 
         </Grid> 
        </ControlTemplate> 
       </Setter.Value> 
      </Setter> 
     </Style> 

編輯

您可以直接給保證金到一個tabpanel的tabcontrol的控件模板

檢查裏面的鏈接,更

http://www.switchonthecode.com/tutorials/the-wpf-tab-control-inside-and-out

+0

謝謝。這似乎做到了。魔術似乎在TabPanel中。我還不明白,但我相信這就是我想要的。 – Michael 2011-03-23 05:40:21