DockPanel的元素共享相同的滚动条?

Gui*_*shy 1 wpf xaml scrollview dockpanel

这是我的代码:

<ScrollViewer Grid.Row="2" CanContentScroll="True">
      <DockPanel>
           <TreeView x:Name="tView" DockPanel.Dock="Top" VerticalAlignment="Stretch">
               [...]
           </TreeView>

           <TreeView Name="pluginsView" DockPanel.Dock="Top" VerticalAlignment="Stretch">
               [...]
           </TreeView>
      </DockPanel>
</ScrollViewer>
Run Code Online (Sandbox Code Playgroud)

我必须定义2个TreeViews.有相同的"区域"(平均相同的[行,列])所以我不得不使用Panel.我使用了StackPanel,但显示器不是我想要的.我使用ScrollViewer,以便当它们不垂直适合"区域"的空间时,我得到2个TreeViews的常见滚动条.

我遇到的问题是水平的.当我的2个TreeView中的一个太"大"时,我得到了一个滚动条,但是只有TreeView太大了,所以当我滚动时,只有一个TreeView水平移动.我想要的是当我滚动时,我的两个TreeView都水平移动.

我不知道它是否足够清楚,如果不清楚我可以上传截图!

我也尝试了这个代码,但它也不起作用:

<ScrollViewer Grid.Row="2" CanContentScroll="True">
      <Grid Grid.Row="2">
           <Grid.RowDefinitions>
               <RowDefinition Height="Auto" />
               <RowDefinition Height="Auto" />
           </Grid.RowDefinitions>
           <TreeView Grid.Row="0" x:Name="tView" DockPanel.Dock="Top" VerticalAlignment="Stretch">
               [...]
           </TreeView>

           <TreeView Grid.Row="1" Name="pluginsView" DockPanel.Dock="Top" VerticalAlignment="Stretch">
               [...]
           </TreeView>
      </DockPanel>
</ScrollViewer>
Run Code Online (Sandbox Code Playgroud)

但我得到了完全相同的问题...... :(

Rac*_*hel 6

听起来它是使用TreeView的内部ScrollViewer滚动内容,而不是外部ScrollViewer.

通常这是因为内部的内容ScrollViewer在某种程度上受到限制,因此请确保您不TreeView以任何方式限制或它的父面板的大小.这包括将Vertical/Horizo​​nal Aligment设置为Stretch.

这是一个可以在两个方向上平滑滚动的示例.我有点惊讶于我必须HorizontalScrollBarVisibility<ScrollViewer>标签中设置才能使水平ScrollBar显示出来.

<Border BorderBrush="Black" BorderThickness="2" Height="100" Width="100">
    <ScrollViewer CanContentScroll="True"
                  HorizontalScrollBarVisibility="Auto"  
                  VerticalScrollBarVisibility="Auto">
        <DockPanel>
            <Rectangle Height="75" Width="150" Fill="Red" DockPanel.Dock="Top" />
            <Rectangle Height="75" Width="150" Fill="Blue" />
        </DockPanel>
    </ScrollViewer>
</Border>
Run Code Online (Sandbox Code Playgroud)