Wpf 如何在tabControl中创建垂直滚动的scrollviewer?

Wpf 如何在tabControl中创建垂直滚动的scrollviewer?,wpf,scrollview,tabcontrol,Wpf,Scrollview,Tabcontrol,我想使我的TabControl可以垂直滚动,但我似乎做不到。下面的示例表现为根本没有scrollviewer。我甚至尝试将TabControl放在scrollviewer中,或者将其全部放在网格中,并限制网格的高度,但没有任何效果 <DataTemplate x:Key="tabControlTemplate"> <TabControl ItemsSource="{Binding guiItems}" DisplayMemberPath

我想使我的TabControl可以垂直滚动,但我似乎做不到。下面的示例表现为根本没有scrollviewer。我甚至尝试将TabControl放在scrollviewer中,或者将其全部放在网格中,并限制网格的高度,但没有任何效果

    <DataTemplate x:Key="tabControlTemplate">

                <TabControl ItemsSource="{Binding guiItems}" DisplayMemberPath="Title" Height="Auto" Template="{StaticResource mainTabControlTemplateEx}">
                    <TabControl.ContentTemplate>
                            <DataTemplate> 
                                <ScrollViewer Grid.Row="1" VerticalScrollBarVisibility="Auto" CanContentScroll="True">
                                    <StackPanel Margin="2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                                          <ItemsControl ItemsSource="{Binding guiItems }" ItemTemplateSelector="{DynamicResource templateSelector}"/>
                                    </StackPanel>
                                </ScrollViewer>
                            </DataTemplate>
                     </TabControl.ContentTemplate>
                </TabControl>

    </DataTemplate>

实际问题并不清楚。 你看不到scrollviewer,里面的内容被剪辑了吗?请确认情况是否如此

如果问题是您看到的整个内容占用了所有可用空间,并且您希望使用scroll viewer进行控制,则需要在scroll viewer上设置“MaxHeight”属性。这将限制DataTemplate的高度,如果内部内容超出MaxHeight,则verticall滚动条将可见


希望这会有所帮助。

您是否尝试过显式地使用
VerticalScrollBarVisibility=“Visible”
选项,我也尝试过。它所做的只是显示一些灰色的滚动条。