您的ItemsControl的ScrollViewer是否有內容滾動設置?編輯2:正如Dan所說,只要您嘗試平滑滾動,就會失去虛擬化。我不知道你的要求是什麼,但一個潛在的解決方法可能是類似以下內容:
<Window x:Class="TestApp11.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
xmlns:l="clr-namespace:TestApp11"
Title="Window1" Height="200" Width="200">
<Grid>
<ItemsControl>
<ItemsControl.Template>
<ControlTemplate>
<ScrollViewer CanContentScroll="True" VirtualizingStackPanel.IsVirtualizing="True" VirtualizingStackPanel.VirtualizationMode="Recycling">
<ItemsPresenter />
</ScrollViewer>
</ControlTemplate>
</ItemsControl.Template>
<ItemsControl.ItemTemplate>
<DataTemplate DataType="{x:Type ListBoxItem}">
<ScrollViewer ScrollViewer.VerticalScrollBarVisibility="Auto" MaxHeight="160">
<Border Height="200" Width="140" BorderBrush="Red" BorderThickness="10" Margin="1" Background="Blue" />
</ScrollViewer>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel VirtualizingStackPanel.VirtualizationMode="Recycling" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ContentElement />
<ContentElement />
<ContentElement />
<ContentElement />
<ContentElement />
<ContentElement />
<ContentElement />
<ContentElement />
<ContentElement />
<ContentElement />
<ContentElement />
<ContentElement />
<ContentElement />
<ContentElement />
<ContentElement />
<ContentElement />
<ContentElement />
</ItemsControl>
</Grid>
</Window>
從本質上講,你可以有ItemTemplate中緊裹的ScrollViewer內的用戶控件項目。我沒有在我的示例中顯示它,但是您可以將ScrollViewer的MaxHeight(ItemTemplate內)綁定到可視區域的高度,然後垂直滾動條僅在您的UserControl太大而不能顯示適合在屏幕上。
我可以看到這可能是太難看的解決方案給客戶,但在這種情況下,我認爲唯一的選擇是去丹建議的路線。
您能否提供一些示例xaml來顯示您目前正在做什麼來實現此目的?我會發現看你如何去實現你的ItemsControl很有幫助。 – Scott 2011-04-04 15:21:11