■ VirtualizingStackPanel 클래스의 IsVirtualizing/VirtualizationMode 속성을 사용해 대용량 데이터를 바인딩하는 방법을 보여준다.
▶ StringCollection.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
using System.Collections.ObjectModel; namespace TestProject { /// <summary> /// 문자열 컬렉션 /// </summary> public class StringCollection : ObservableCollection<string> { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - StringCollection() /// <summary> /// 생성자 /// </summary> public StringCollection() { for(int i = 0; i < 1000000; ++i) { Add("항목 " + i.ToString()); } } #endregion } } |
▶ MainWindow.xaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
<Window x:Class="TestProject.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:TestProject" Width="800" Height="600" Title="VirtualizingStackPanel 클래스 : IsVirtualizing/VirtualizationMode 속성을 사용해 대용량 데이터 바인딩하기" FontFamily="나눔고딕코딩" FontSize="16"> <Window.Resources> <local:StringCollection x:Key="StringCollectionKey" /> </Window.Resources> <Grid> <ListBox VirtualizingStackPanel.IsVirtualizing="True" VirtualizingStackPanel.VirtualizationMode="Recycling" ItemsSource="{StaticResource StringCollectionKey}" /> </Grid> </Window> |