2017-05-01 1 views
1

UI를 만들기 위해 C#/WPF를 사용하고 있습니다.WPF : TabControl에서 헤더 영역의 너비 최대 크기 제한

내 UI에는 사용자의 편의를 위해 탭 컨트롤의 헤더 영역에 버튼이 있습니다.

Last tab

: 많은 탭이 추가되는 경우 (이것은 다중 행 중 하나를 가지고있는 경우 나)

문제는, 마지막에 첨부 된 사진에서 붉은 사각형처럼 그 버튼에 의해 커버 될 수있다

TabControl의 머리글 영역의 최대 너비를 제한 할 수 있지만 TabItems의 콘텐츠 영역의 너비를 유지하는 방법이 있습니까?

현재 XAML :

<Grid> 
    <Grid HorizontalAlignment="Stretch"> 
     <TabControl BorderThickness="0,0,0,1" Margin="0,0,0,0"> 
      <TabItem MinWidth="130" Height="27" Content="Title" /> 
      <TabItem MinWidth="130" Height="27" Content="Title" /> 
      <TabItem MinWidth="130" Height="27" Content="Title" /> 
      <TabItem MinWidth="130" Height="27" Content="Title" /> 
      <TabItem MinWidth="130" Height="27" Content="Title" /> 
      <TabItem MinWidth="130" Height="27" Content="Title" /> 
      <TabItem MinWidth="130" Height="27" Content="Title" /> 
      <TabItem MinWidth="130" Height="27" Content="Title" /> 
     </TabControl> 
    </Grid> 
    <StackPanel Orientation="Horizontal" HorizontalAlignment="Right"> 
     <Button Margin="0,2,5,0" HorizontalAlignment="Left" Height="20" Width="22" VerticalAlignment="top" Content="+" /> 
     <Button Width="65" Height="25" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,0,1,1" Content="Close" /> 
    </StackPanel> 
</Grid> 

`

참고 : 내 마음의 위에, 나는 부모를 오버 플로우하기 위해 TabItems 마이너스 마진을 사용할 수 있습니다 (을 TabControl)의 폭, 그러나 그것은 좋은 해결 방법이 될 수 있습니다.

이 경우 적절한 접근 방법을 알려주십시오.

답변

1

당신은이 같은 "ButtonPanel"를 삽입, 더 구체적은 ControlTemplate을 자신을 TabControl 스타일을 정의하거나 할 수 있습니다

<TabControl.Style> 
        <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> 
             <Grid.ColumnDefinitions> 
              <ColumnDefinition Width="*" /> 
              <ColumnDefinition Width="Auto" /> 
             </Grid.ColumnDefinitions> 
             <VisualStateManager.VisualStateGroups> 
              <VisualStateGroup x:Name="CommonStates"> 
               <VisualState x:Name="Disabled"> 
                <Storyboard> 
                 <ColorAnimationUsingKeyFrames Storyboard.TargetName="Border" 
                         Storyboard.TargetProperty="(Border.BorderBrush).(SolidColorBrush.Color)"> 
                  <EasingColorKeyFrame KeyTime="0" 
                       Value="#FFAAAAAA" /> 
                 </ColorAnimationUsingKeyFrames> 
                </Storyboard> 
               </VisualState> 
              </VisualStateGroup> 
             </VisualStateManager.VisualStateGroups> 
             <TabPanel x:Name="HeaderPanel" 
                Grid.Row="0" 
                Panel.ZIndex="1" 
                Margin="0,0,4,-1" 
                IsItemsHost="True" 
                KeyboardNavigation.TabIndex="1" 
                Background="Transparent" /> 
             <StackPanel x:Name="ButtonPanel" Grid.Column="1" Orientation="Horizontal"> 
              <Button Margin="0,2,5,0" 
                HorizontalAlignment="Left" 
                Height="20" 
                Width="22" 
                VerticalAlignment="top" 
                Content="+" /> 
              <Button Width="65" 
                Height="25" 
                HorizontalAlignment="Right" 
                VerticalAlignment="Top" 
                Margin="0,0,1,1" 
                Content="Close" /> 
             </StackPanel> 
             <Border x:Name="Border" 
               Grid.Row="1" 
               Grid.ColumnSpan="2" 
               BorderThickness="1" 
               CornerRadius="2" 
               KeyboardNavigation.TabNavigation="Local" 
               KeyboardNavigation.DirectionalNavigation="Contained" 
               KeyboardNavigation.TabIndex="2"> 
              <Border.Background> 
               <LinearGradientBrush EndPoint="0.5,1" 
                    StartPoint="0.5,0"> 
                <GradientStop Color="{DynamicResource ContentAreaColorLight}" 
                    Offset="0" /> 
                <GradientStop Color="{DynamicResource ContentAreaColorDark}" 
                    Offset="1" /> 
               </LinearGradientBrush> 
              </Border.Background> 
              <Border.BorderBrush> 
               <SolidColorBrush Color="{DynamicResource BorderMediumColor}" /> 
              </Border.BorderBrush> 
              <ContentPresenter x:Name="PART_SelectedContentHost" 
                   Margin="4" 
                   ContentSource="SelectedContent" /> 
             </Border> 
            </Grid> 
           </ControlTemplate> 
          </Setter.Value> 
         </Setter> 
        </Style> 
       </TabControl.Style>