ฉันมีตัวอย่างทดสอบต่อไปนี้:
<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
เป็นค่าคงที่