■ GridControl 엘리먼트에서 ICollectionView 데이터 소스를 바인딩하는 방법을 보여준다.
▶ 예제 코드 (C#)
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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
using System.Collections.Generic; using System.Windows.Data; using System.ComponentModel; /// <summary> /// 뷰 모델 /// </summary> public class ViewModel { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// 컬렉션 뷰 /// </summary> private ICollectionView collectionView; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 컬렉션 뷰 - CollectionView /// <summary> /// 컬렉션 뷰 /// </summary> public ICollectionView CollectionView { get { if(this.collectionView == null) { List<SampleData> list = new List<SampleData>(); for(int i = 0; i < 100; i++) { list.Add(new SampleData() { Number1 = i, Number2 = i * 10, Text1 = "row " + i, Text2 = "ROW " + i }); } this.collectionView = new ListCollectionView(list); } return this.collectionView; } } #endregion } |
▶ 예제 코드 (XAML)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
<Grid xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid" xmlns:local="clr-namespace:HowToBindTheDXGridToICollectionView"> <Grid.DataContext> <local:ViewModel /> </Grid.DataContext> <dxg:GridControl x:Name="gridControl" ItemsSource="{Binding Path=CollectionView}" AutoGenerateColumns="AddNew"> <dxg:GridControl.View> <dxg:TableView IsSynchronizedWithCurrentItem="True" ShowGroupPanel="False" AllowGrouping="False" AutoWidth="True" AllowEditing="False" ShowAutoFilterRow="True" /> </dxg:GridControl.View> </dxg:GridControl> </Grid> |