如何在tabControl中创建垂直滚动滚动查看器?

时间:2014-02-25 19:42:56

标签: wpf scrollview tabcontrol

我想让我的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>

1 个答案:

答案 0 :(得分:0)

问题不清楚实际问题。 你没有看到scrollviewer并且里面的内容被剪裁了?如果是这种情况,请确认。

如果问题是您要看到整个内容占用所有可用空间,并且您想使用滚动查看器控制它,那么您需要在滚动查看器上设置“MaxHeight”属性。这将限制DataTemplate的高度,如果内部内容超出MaxHeight,则会使verticall滚动条可见。

希望有所帮助。

相关问题