我有一個WPF應用程序,我顯示並隱藏大量的UserControl對象。 XAML代碼如下所示:緩存UserControl對象
<ItemsControl ItemsSource="{Binding Path=MyListOfStuff}" >
<Controls:MyControl Stuff="{Binding}"/>
</ItemsControl>
創建這些對象需要很長時間。分析顯示'InitializeComponent'需要大量的MyControl對象。我想預先創建這些對象以減少這個時間。我怎樣才能做到這一點?我仍然需要xaml代碼,並且不想僅用代碼來替換它。
無法使用虛擬化,因爲列表中的項有時比視圖大,所以CanContentScroll必須爲False。
看看這個:http://stackoverflow.com/questions/2783845/wpf-virtualizing-an-itemscontrol雖然我不確定是否virualizing會幫助你的情況,因爲你顯示和隱藏不滾動。 – Ray 2012-01-10 14:12:17
查看http://stackoverflow.com/questions/22218506/wpf-canvas-based-itemscontrol-with-minimum-recycled-items/22220980#comment33743843_22220980 CachingItemsControl實現 – 2014-03-07 10:21:23