WPF tabcontrol中标题的工具栏使tabcontrol无法在Tabitem之间切换

问题描述

我在wpf中有一个tabcontrol。我编辑了tabcontrol模板。我将标题更改为工具栏,以在工具栏面板和工具栏溢出面板中获取标题

这是我的tabcontrol的模板

                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate targettype="{x:Type TabControl}">
                                        <Grid x:Name="templateRoot" 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>
                                            <WrapPanel  Grid.Column="0" Background="#f7f7f7">
                                                <Grid HorizontalAlignment="Stretch">
                                                    <Grid.ColumnDeFinitions>
                                                        <ColumnDeFinition></ColumnDeFinition>
                                                        <ColumnDeFinition Width="0"></ColumnDeFinition>
                                                    </Grid.ColumnDeFinitions>
                                                        <ToolBar x:Name="headerPanel" ItemsSource="{Binding RelativeSource={RelativeSource TemplatedParent},Path=Items}" Margin="2,2,0" Grid.Row="0" KeyboardNavigation.TabIndex="1" Panel.ZIndex="1" Grid.Column="0" ToolBarTray.IsLocked="True">
                                                   
                                                        </ToolBar>
                                                </Grid>
                                            </WrapPanel>
                                            <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">
                                                <Grid>
                                                <ContentPresenter x:Name="PART_SelectedContentHost" ContentSource="SelectedContent" Margin="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                                                </Grid>
                                            </Border>
                                        </Grid>
                                        <ControlTemplate.Triggers>
                                            <Trigger Property="TabStripPlacement" Value="Bottom">
                                                <Setter Property="Grid.Row" TargetName="headerPanel" Value="1"/>
                                                <Setter Property="Grid.Row" TargetName="contentPanel" Value="0"/>
                                                <Setter Property="Height" TargetName="RowDeFinition0" Value="*"/>
                                                <Setter Property="Height" TargetName="RowDeFinition1" Value="Auto"/>
                                                <Setter Property="Margin" TargetName="headerPanel" Value="2,2"/>
                                            </Trigger>
                                            <Trigger Property="TabStripPlacement" Value="Left">
                                                <Setter Property="Grid.Row" TargetName="headerPanel" Value="0"/>
                                                <Setter Property="Grid.Row" TargetName="contentPanel" Value="0"/>
                                                <Setter Property="Grid.Column" TargetName="headerPanel" Value="0"/>
                                                <Setter Property="Grid.Column" TargetName="contentPanel" Value="1"/>
                                                <Setter Property="Width" TargetName="ColumnDeFinition0" Value="Auto"/>
                                                <Setter Property="Width" TargetName="ColumnDeFinition1" Value="*"/>
                                                <Setter Property="Height" TargetName="RowDeFinition0" Value="*"/>
                                                <Setter Property="Height" TargetName="RowDeFinition1" Value="0"/>
                                                <Setter Property="Margin" TargetName="headerPanel" Value="2,2"/>
                                            </Trigger>
                                            <Trigger Property="TabStripPlacement" Value="Right">
                                                <Setter Property="Grid.Row" TargetName="headerPanel" Value="0"/>
                                                <Setter Property="Grid.Row" TargetName="contentPanel" Value="0"/>
                                                <Setter Property="Grid.Column" TargetName="headerPanel" Value="1"/>
                                                <Setter Property="Grid.Column" TargetName="contentPanel" Value="0"/>
                                                <Setter Property="Width" TargetName="ColumnDeFinition0" Value="*"/>
                                                <Setter Property="Width" TargetName="ColumnDeFinition1" Value="Auto"/>
                                                <Setter Property="Height" TargetName="RowDeFinition0" Value="*"/>
                                                <Setter Property="Height" TargetName="RowDeFinition1" Value="0"/>
                                                <Setter Property="Margin" TargetName="headerPanel" Value="0,2"/>
                                            </Trigger>
                                            <Trigger Property="IsEnabled" Value="false">
                                                <Setter Property="TextElement.Foreground" TargetName="templateRoot" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                                            </Trigger>
                                        </ControlTemplate.Triggers>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>

使用此选项卡可以根据需要创建选项卡,但是我无法在选项卡之间切换。

我看过这篇文章并使用了工具栏 TabControl with single line TabPanel and Overflow Panel

任何有助于在标签之间进行切换的帮助都会有用。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)