ScrollViewer 不滚动ScrollViewer

2023-09-06 06:25:43 作者:超拽的少爷

我想要一个包含 3 个组件的接口,这些组件一个接一个.第一个是 ListView,另外两个是 Grid.

I would like to have an interface with 3 components one next to the other. The first would be a ListView and the two others being Grids.

由于组件会在右侧溢出,所以我想将它们放在 ScrollViewer 中.我没有成功.我试着做一个非常简单的例子来尝试,但连例子都失败了.

Since the components will overflow on the right, I want to put them in a ScrollViewer. I did not succeed. I tried to do a really simple example to try, but even the example fails.

    <ScrollViewer Grid.Column="1" Grid.Row="2" HorizontalAlignment="Left" VerticalAlignment="Top" Width="600" Height="400">
        <StackPanel Width="1200" Height="400" Orientation="Horizontal">
            <Border Background="AntiqueWhite" Width="400" Height="400" HorizontalAlignment="Left" VerticalAlignment="Top"  />
            <Border Background="Blue" Width="400" Height="400" HorizontalAlignment="Left" VerticalAlignment="Top" />
            <Border Background="LimeGreen" Width="400" Height="400" HorizontalAlignment="Left" VerticalAlignment="Top" />
        </StackPanel>
    </ScrollViewer>

如您所见,ScrollViewer 位于网格内部.我错过了什么?

As you can see, the ScrollViewer is Inside a Grid. What did I miss?

推荐答案

尝试在滚动查看器上设置这些属性:-

Try settings these properties on the scroll viewer:-

 <ScrollViewer VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Visible" ZoomMode="Disabled" Grid.Column="1" Grid.Row="2" HorizontalAlignment="Left" VerticalAlignment="Top" Width="600" Height="400">
    <StackPanel Width="1200" Height="400" Orientation="Horizontal">
        <Border Background="AntiqueWhite" Width="400" Height="400" HorizontalAlignment="Left" VerticalAlignment="Top"  />
        <Border Background="Blue" Width="400" Height="400" HorizontalAlignment="Left" VerticalAlignment="Top" />
        <Border Background="LimeGreen" Width="400" Height="400" HorizontalAlignment="Left" VerticalAlignment="Top" />
    </StackPanel>
</ScrollViewer>

这对我来说很正常!