1

次のテストサンプルがあります。

<Window x:Class="WpfScrollTest.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="200" Width="200">
    <Border>
        <StackPanel>
            <Label Width="Auto" Height="Auto" Content="Text to mess up the scrollview"/>
                <ScrollViewer Height="{Binding RelativeSource={RelativeSource FindAncestor, 
                        AncestorType={x:Type Border}}, Path=ActualHeight}">
                    <StackPanel>
                        <Button MinWidth="100" MinHeight="100" Content="Button"/>
                        <Button MinWidth="100" MinHeight="100" Content="Button"/>
                    </StackPanel>
                </ScrollViewer>
            </StackPanel>
    </Border>
</Window>

これが作成されます:

スクロールバーの下部がありません

ScrollViewer.Height私の質問は、スクロールバーの下部を表示しながら動的に設定するにはどうすればよいですか? 私のサンプルでは、Height​​ のScrollViewerが長すぎるため、Label上記の ..

HeightのをScrollViewer静的な値に固定したくありません。

4

1 に答える 1

3

Stackpanel は子のサイズを尊重しないため、外側の StackPanel をグリッドに削除することをお勧めします。ScrollViewer.Height バインディングを削除します。ここで、Grid 用に 2 つの RowDefinition を作成し、Label を Grid.Row=0 に、ScrollViwer を Grid.Row=1 に配置するだけです。

コードは以下です。ここでの私のヒントは、必要な場合にのみ StackPanel/Canvas を使用し、内側のレベルに使用することです。非常に動的なレイアウトを取得するには、Grid をもっと使用してみてください。

  <Border>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Label Grid.Row="0" Width="Auto" Height="Auto" Content="Text to mess up the scrollview"/>
        <ScrollViewer Grid.Row="1" >
            <StackPanel>
                <Button MinWidth="100" MinHeight="100" Content="Button"/>
                <Button MinWidth="100" MinHeight="100" Content="Button"/>
            </StackPanel>
        </ScrollViewer>
    </Grid>
</Border>
于 2009-10-19T05:19:27.820 に答える