2012-04-12 11 views
0
<Border Background="#FF260F54"> 
    <TabControl Name="MyTabCtrl" SelectionChanged="MyTabCtrl_SelectionChanged" > 
     <TabItem Name="TItem01" Header="01"> 
      <TextBlock>TItem01</TextBlock> 
     </TabItem> 
     <TabItem Name="TItem02" Header="02"> 
      <TextBlock>TItem02</TextBlock> 
     </TabItem> 
    </TabControl> 
</Border> 

TItem01を左に200ピクセル移動して、TItem02を表示したいとします。 どうすればよいですか?私を助けてください。どうもありがとうございました!これは最も簡単な方法であればTabControlのTabItemを移動するにはどうしたらいいですか?

答えて

1

は分からないのですが、私はデフォルトのTabControlのスタイルを変更します:

<SolidColorBrush x:Key="WindowBackgroundBrush" Color="#FFF" /> 
<SolidColorBrush x:Key="SolidBorderBrush" Color="#888" /> 
<SolidColorBrush x:Key="DisabledForegroundBrush" Color="#888" /> 
<SolidColorBrush x:Key="DisabledBorderBrush" Color="#AAA" /> 
<Style TargetType="{x:Type TabControl}"> 
    <Setter Property="OverridesDefaultStyle" Value="True" /> 
    <Setter Property="SnapsToDevicePixels" Value="True" /> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="{x:Type TabControl}"> 
       <Grid KeyboardNavigation.TabNavigation="Local"> 
        <Grid.RowDefinitions> 
         <RowDefinition Height="Auto"/> 
         <RowDefinition Height="*"/> 
        </Grid.RowDefinitions> 
        <TabPanel 
         Name="HeaderPanel" 
         Grid.Row="0" 
         Panel.ZIndex="1" 
         Margin="200,0,4,-1" 
         IsItemsHost="True" 
         KeyboardNavigation.TabIndex="1" 
         Background="Transparent" /> 
        <Border 
         Name="Border" 
         Grid.Row="1" 
         Background="{StaticResource WindowBackgroundBrush}" 
         BorderBrush="{StaticResource SolidBorderBrush}" 
         BorderThickness="1" 
         CornerRadius="2" 
         KeyboardNavigation.TabNavigation="Local" 
         KeyboardNavigation.DirectionalNavigation="Contained" 
         KeyboardNavigation.TabIndex="2" > 
         <ContentPresenter 
          Name="PART_SelectedContentHost" 
          Margin="4" 
          ContentSource="SelectedContent" /> 
        </Border> 
       </Grid> 
       <ControlTemplate.Triggers> 
        <Trigger Property="IsEnabled" Value="False"> 
         <Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}" /> 
         <Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource DisabledBorderBrush}" /> 
        </Trigger> 
       </ControlTemplate.Triggers> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 

ContolTemplateTabPanel要素のMarginプロパティを注意してください?そのマージンは、タブの開始位置を決定します。デフォルトでは0,0,4、-1です。あなたの要件に合わせて200,0,4、-1に変更しました。

私がそのスタイルをどのように作り出したのか疑問に思うなら、いくつかの方法があります。 Expression Blendを使用するのが最も簡単です。コントロールを "中断"し、デフォルトのパーツとスタイルを公開するオプションがあります。もう一つの方法は、MSDNにはControlTemplatesが公開されているため検索するだけです。 (私は第2の方法を使用した)

関連する問題