C # WPF Custom Vertical TabControl Переполнение прокрутки - PullRequest
0 голосов
/ 16 сентября 2018

Есть ли в сообществе кто-то, кто может мне помочь?

Вот вертикаль TabControl У меня так далеко:

<Window.Resources>
    <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.ColumnDefinitions>
                            <ColumnDefinition Width="25" MinWidth="25" />
                            <ColumnDefinition Width="*" />
                        </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>
                        <ContentPresenter x:Name="PART_SelectedContentHost"
                                          Grid.Column="1"
                                          Margin="0"
                                          ContentSource="SelectedContent" />
                        <StackPanel x:Name="HeaderPanel"
                                    Grid.Row="0"
                                    Margin="0,0,4,-1"
                                    Panel.ZIndex="1"
                                    Background="Transparent"
                                    IsItemsHost="True"
                                    KeyboardNavigation.TabIndex="1" />
                        <Border x:Name="Border"
                                Grid.Row="1"
                                BorderThickness="1"
                                CornerRadius="2"
                                KeyboardNavigation.DirectionalNavigation="Contained"
                                KeyboardNavigation.TabIndex="2"
                                KeyboardNavigation.TabNavigation="Local" />
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    <Style TargetType="{x:Type TabItem}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type TabItem}" >
                    <Grid x:Name="Root">
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="SelectionStates">
                                <VisualState x:Name="Unselected" />
                                <VisualState x:Name="Selected">
                                    <Storyboard>
                                        <ColorAnimationUsingKeyFrames Storyboard.TargetName="Border" Storyboard.TargetProperty="(Border.BorderBrush).(SolidColorBrush.Color)">
                                            <EasingColorKeyFrame KeyTime="0" Value="#FF0000FF" />
                                        </ColorAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Normal" />
                                <VisualState x:Name="MouseOver" />
                                <VisualState x:Name="Disabled" />
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <Border x:Name="Border"
                                Margin="0,0,0,0"
                                BorderBrush="Gainsboro"
                                BorderThickness="0,0,2,0" />
                        <TextBlock x:Name="TabName" Margin="0,10,0,10" Text="{Binding Name,Mode=OneWay}" >
                            <TextBlock.LayoutTransform>
                                <TransformGroup>
                                    <ScaleTransform />
                                    <SkewTransform />
                                    <RotateTransform Angle="-90" />
                                    <TranslateTransform />
                                </TransformGroup>
                            </TextBlock.LayoutTransform>
                        </TextBlock>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</Window.Resources>

<TabControl x:Name="MyTabControl"
            Grid.Row="1"
            Margin="0,0,5,5"
            HorizontalAlignment="Stretch"
            VerticalAlignment="Stretch" 
            SelectionChanged="MyTabControl_SelectionChanged" >
    <TabControl.ItemsSource>
        <CompositeCollection>
            <CollectionContainer Collection="{Binding MyDataSource}"/>
        </CompositeCollection>
    </TabControl.ItemsSource>
    <TabControl.ContentTemplate>
        <DataTemplate>
            <ListView ItemsSource="{Binding MyDataSource}"
                      VerticalAlignment="Stretch"
                      SelectionChanged="MyDetailList_SelectionChanged">
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal">
                            <Label Content="{Binding Name,Mode=OneWay}" HorizontalAlignment="Stretch" BorderThickness="0"/>
                            <Label Content="{Binding Count,Mode=OneWay}" ContentStringFormat="({0})" Foreground="Gray"/>
                        </StackPanel>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>
        </DataTemplate>
    </TabControl.ContentTemplate>
</TabControl>

выглядит так:

vertical scrollbar

И что я хотел бы получить, это, но работает:

        <TabControl x:Name="MyTabControl" 
                    Grid.Row="1"
                    Margin="0,0,5,5"
                    HorizontalAlignment="Stretch"
                    VerticalAlignment="Stretch" 
                    SelectionChanged="MyTabControl_SelectionChanged"                            
                    Template="{DynamicResource TabOverflowTemplate}" 
                    IsSynchronizedWithCurrentItem="True" >

            <TabControl.Resources>
                <Style x:Key="TabScrollerRepeatButtonStyle" TargetType="{x:Type RepeatButton}">
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate>
                                <Border Background="sc#1, 0.366693377, 0.372125238, 0.6931424">
                                    <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" Content="{TemplateBinding ContentControl.Content}"/>
                                </Border>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>

                <ControlTemplate x:Key="TabOverflowTemplate" TargetType="{x:Type TabControl}">
                    <Grid x:Name="Grid" KeyboardNavigation.TabNavigation="Local">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="*"/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>
                        <Border Grid.Row="1" Grid.Column="0" x:Name="ContentPanel" BorderBrush="#FFD0CEBF" BorderThickness="1,1,2,2" KeyboardNavigation.TabIndex="2" KeyboardNavigation.TabNavigation="Local" KeyboardNavigation.DirectionalNavigation="Contained">
                            <Border x:Name="Border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
                                <Border Background="{TemplateBinding Background}" x:Name="Border1">
                                    <ContentPresenter DataContext="{x:Null}" Margin="{TemplateBinding Padding}" x:Name="PART_SelectedContentHost" Content="{TemplateBinding SelectedContent}" ContentTemplate="{TemplateBinding SelectedContentTemplate}" ContentTemplateSelector="{TemplateBinding SelectedContentTemplateSelector}" ContentSource="SelectedContent"/>
                                </Border>
                            </Border>
                        </Border>
                        <ScrollViewer x:Name="HeaderPanel" Grid.Row="1" Grid.Column="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0,0,0,0" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Auto">
                            <ScrollViewer.Style>
                                <Style TargetType="{x:Type ScrollViewer}">
                                    <Setter Property="Template">
                                        <Setter.Value>
                                            <ControlTemplate>
                                                <Grid Margin="0,0,0,0" Grid.Row="0" Grid.Column="0" x:Name="HeaderPanel">
                                                    <Grid.ColumnDefinitions>
                                                        <ColumnDefinition Width="Auto"/>
                                                        <ColumnDefinition Width="Auto"/>
                                                    </Grid.ColumnDefinitions>
                                                    <Grid.RowDefinitions>
                                                        <RowDefinition Height="25"/>
                                                        <RowDefinition Height="*"/>
                                                        <RowDefinition Height="25"/>
                                                    </Grid.RowDefinitions>
                                                    <RepeatButton Grid.Column="0" Grid.Row="0" Content="up" Command="ScrollBar.LineUpCommand" Style="{DynamicResource TabScrollerRepeatButtonStyle}" />
                                                    <ScrollContentPresenter Grid.Column="0" Grid.Row="1" Content="{TemplateBinding ScrollViewer.Content}" />
                                                    <RepeatButton Grid.Column="0" Grid.Row="2" Content="down" Command="ScrollBar.LineDownCommand" Style="{DynamicResource TabScrollerRepeatButtonStyle}" />
                                                </Grid>
                                            </ControlTemplate>
                                        </Setter.Value>
                                    </Setter>
                                </Style>
                            </ScrollViewer.Style>
                            <StackPanel IsItemsHost="true" Orientation="Vertical" Background="{x:Null}" KeyboardNavigation.TabIndex="1" />
                        </ScrollViewer>
                    </Grid>
                </ControlTemplate>
            </TabControl.Resources>

            <TabControl.ItemsSource>
                <CompositeCollection>
                    <CollectionContainer Collection="{Binding MyDataSource}"/>
                </CompositeCollection>
            </TabControl.ItemsSource>

            <TabControl.ContentTemplate>
                <DataTemplate>
                    <ListView ItemsSource="{Binding MyDataSource}"
                              VerticalAlignment="Stretch"
                              SelectionChanged="MyDetailList_SelectionChanged">
                        <ListView.ItemTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal">
                                    <Label Content="{Binding Name,Mode=OneWay}" HorizontalAlignment="Stretch" BorderThickness="0"/>
                                    <Label Content="{Binding Count,Mode=OneWay}" ContentStringFormat="({0})" Foreground="Gray"/>
                                </StackPanel>
                            </DataTemplate>
                        </ListView.ItemTemplate>
                    </ListView>
                </DataTemplate>
            </TabControl.ContentTemplate>
        </TabControl>

выглядит так:

aim

Однако пока результат ... не совсем TabControl Переполнение, кажется, работает Отлично, Scrollable на Hover и Up и Down работает отлично .. Только содержимое ListView теперь полностью скрыто: x

Чего я бы очень хотел добиться, так это функциональности, которую он имеет сейчас. Похож на это , но по вертикали

Не стесняйтесь пролить свет на мои ошибки.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...