您應該將ListView的MinHeight屬性設置爲您希望ScrollViewer的ScrollBar變爲或啓用的特定高度。 ListView的Height屬性應該綁定到ScrollViewer的Height屬性。然後,當窗口的高度降低到隱藏ListView中List的一部分的高度時,ListView的ScrollBar apears。當ListView的高度達到其MinHeight ScrollViewer的ScrollBar apears。
這是XAML代碼:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<ScrollViewer VerticalScrollBarVisibility="Auto">
<DockPanel>
<ListView x:Name="listView1" DockPanel.Dock="Bottom" MinHeight="100" Height="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=ScrollViewer, AncestorLevel=1}, Path=ActualHeight}"/>
</DockPanel>
</ScrollViewer>
</Grid>
</Window>
我沒有檢查這個時間,但我認爲你應該爲ListBox設置最小高度,然後使用轉換器將ListBox的實際高度綁定到ScrollViewer的實際高度,以使ScrollViewer的ScrollBar apear之前的ListBox實際高度縮小。然後,只有當ListBox縮小到其最小高度時,ScrollViewer的ScrollBar纔會出現。 希望它有效。 – Seffix 2012-01-09 05:19:26
請看下面的答案。 – Seffix 2012-01-09 07:55:33