2011-05-31 69 views
2

我有一個選項卡控件,我想在右上角添加一個按鈕。需要一個WPF控件建議

> [TabControl] 
> [TabItem1][TabItem2][TabItem3][TabItem4].....blank space...[ settings button] 

如果我將設置按鈕添加到TabControl,它將直接與TabItem4相鄰。

有什麼建議嗎?

+0

「我需要它像在.css文件中一樣漂浮在右上角。」沒有意義... – Peter 2011-05-31 21:43:42

回答

1

爲您的TabControl創建類似於模板內容的內容。

例如

<Grid> 
    <Grid.ColumnDefinitions> 
     <ColumnDefinition Width="*"/> 
     <ColumnDefinition Width="100"/> 
    </Grid.ColumnDefinitions>  
    <TabControl Grid.ColumnSpan="2" > 
      <TabItem Header="TabItem"> 
      </TabItem> 
      <TabItem Header="TabItem"> 
      </TabItem> 
    </TabControl> 
    <Button Grid.Column="1" VerticalAlignment="Top" Height="20"></Button> 
</Grid> 

或者,您可以編輯TabControl模板,根據需要自定義HeaderPanel。

<ControlTemplate TargetType="{x:Type TabControl}"> 
    <Grid ClipToBounds="true" SnapsToDevicePixels="true" KeyboardNavigation.TabNavigation="Local"> 
     <Grid.ColumnDefinitions> 
      <ColumnDefinition x:Name="ColumnDefinition0"/> 
      <ColumnDefinition x:Name="ColumnDefinition1" Width="0"/> 
     </Grid.ColumnDefinitions> 
     <Grid.RowDefinitions> 
      <RowDefinition x:Name="RowDefinition0" Height="Auto"/> 
      <RowDefinition x:Name="RowDefinition1" Height="*"/> 
     </Grid.RowDefinitions> 
     <Grid Grid.Column="0"> 
      <Grid.ColumnDefinitions> 
      <ColumnDefinition Width="*"/> 
      <ColumnDefinition Width="100"/> 
     </Grid.ColumnDefinitions> 
     <TabPanel x:Name="HeaderPanel" Grid.Column="0" IsItemsHost="true" Margin="2,2,2,0" Grid.Row="0" KeyboardNavigation.TabIndex="1" Panel.ZIndex="1"/> 
     <Button Grid.Column="1"> settings </Button> 
    </Grid> 
    <Border x:Name="ContentPanel" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Grid.Column="0" KeyboardNavigation.DirectionalNavigation="Contained" Grid.Row="1" KeyboardNavigation.TabIndex="2" KeyboardNavigation.TabNavigation="Local"> 
     <ContentPresenter x:Name="PART_SelectedContentHost" ContentSource="SelectedContent" Margin="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/> 
    </Border> 
    </Grid> 
</ControlTemplate>