1- namespace DataGridAsyncDemo
1+ #region
2+
3+ using System ;
4+ using System . ComponentModel ;
5+ using System . Diagnostics ;
6+ using System . Timers ;
7+ using System . Windows ;
8+ using System . Windows . Controls ;
9+ using System . Windows . Controls . Primitives ;
10+ using System . Windows . Threading ;
11+ using AlphaChiTech . Virtualization ;
12+ using DataGridAsyncDemo . filtersort ;
13+ using SortDescription = DataGridAsyncDemo . filtersort . SortDescription ;
14+
15+ #endregion
16+
17+ namespace DataGridAsyncDemo
218{
319 #region
420
5- using System ;
6- using System . ComponentModel ;
7- using System . Diagnostics ;
8- using System . Timers ;
9- using System . Windows ;
10- using System . Windows . Controls ;
11- using System . Windows . Controls . Primitives ;
12- using System . Windows . Threading ;
13- using AlphaChiTech . Virtualization ;
14- using filtersort ;
15- using SortDescription = filtersort . SortDescription ;
21+
1622
1723 #endregion
1824
2127 /// </summary>
2228 public partial class MainWindow : Window
2329 {
30+ #region fields
31+
32+ private Timer _filterTimer ;
33+ private VirtualizingObservableCollection < RemoteOrDbDataItem > _myDataVirtualizedAsyncFilterSortObservableCollection = null ;
34+ private RemoteOrDbDataSourceAsyncProxy _myRemoteOrDbDataSourceAsyncProxy = null ;
35+
36+ #endregion
37+
2438 #region constructors
2539
2640 //private VirtualizingObservableCollection<RemoteOrDbDataItem> _myDataVirtualizedAsyncFilterSortObservableCollection;
@@ -39,7 +53,10 @@ public MainWindow()
3953 VirtualizationManager . Instance . UIThreadExcecuteAction = a => Dispatcher . Invoke ( a ) ;
4054 new DispatcherTimer ( TimeSpan . FromSeconds ( 1 ) ,
4155 DispatcherPriority . Background ,
42- delegate { VirtualizationManager . Instance . ProcessActions ( ) ; } ,
56+ delegate
57+ {
58+ VirtualizationManager . Instance . ProcessActions ( ) ;
59+ } ,
4360 Dispatcher ) . Start ( ) ;
4461 }
4562
@@ -50,69 +67,18 @@ public MainWindow()
5067
5168 #endregion
5269
53- #region Asynchrony source filter sort
70+ #region events
5471
55- private VirtualizingObservableCollection < RemoteOrDbDataItem > _myDataVirtualizedAsyncFilterSortObservableCollection = null ;
56- private RemoteOrDbDataSourceAsyncProxy _myRemoteOrDbDataSourceAsyncProxy = null ;
57-
58- public VirtualizingObservableCollection < RemoteOrDbDataItem > MyDataVirtualizedAsyncFilterSortObservableCollection
59- {
60- get
61- {
62- if ( _myDataVirtualizedAsyncFilterSortObservableCollection == null )
63- {
64- _myRemoteOrDbDataSourceAsyncProxy = new RemoteOrDbDataSourceAsyncProxy ( new RemoteOrDbDataSourceEmulation ( ) ) ;
65- //class RemoteOrDbDataSourceAsyncProxy : IPagedSourceProviderAsync<RemoteOrDbDataItem>, IFilteredSortedSourceProviderAsync, IPagedSourceProvider<T>
66- _myDataVirtualizedAsyncFilterSortObservableCollection =
67- new VirtualizingObservableCollection < RemoteOrDbDataItem > ( // BUG ici il faut un IItemSourceProviderAsync<T> asyncProvider
68- // et non un IItemSourceProvider<T> provider
69- new PaginationManager < RemoteOrDbDataItem > ( _myRemoteOrDbDataSourceAsyncProxy ) ) ;
70- }
71- return _myDataVirtualizedAsyncFilterSortObservableCollection ;
72- }
73- }
74-
75- private void TstDataGridAsyncFilterSort_Sorting ( object sender , DataGridSortingEventArgs e )
72+ private void DbgButton_Click ( object sender , RoutedEventArgs e )
7673 {
77- DataGrid grid = sender as DataGrid ;
78-
79- var sortDirection = e . Column . SortDirection ;
80- string sortMemberPath = e . Column . SortMemberPath ;
81-
82- if ( sortDirection == null )
83- {
84- e . Column . SortDirection = ListSortDirection . Ascending ;
85- _myRemoteOrDbDataSourceAsyncProxy . SortDescriptionList . Add ( new SortDescription ( sortMemberPath , ListSortDirection . Ascending ) ) ;
86- }
87- else if ( sortDirection == ListSortDirection . Ascending )
88- {
89- e . Column . SortDirection = ListSortDirection . Descending ;
90- _myRemoteOrDbDataSourceAsyncProxy . SortDescriptionList . Add ( new SortDescription ( sortMemberPath , ListSortDirection . Descending ) ) ;
91- }
92- else if ( sortDirection == ListSortDirection . Descending )
93- {
94- e . Column . SortDirection = null ;
95- _myRemoteOrDbDataSourceAsyncProxy . SortDescriptionList . Remove ( sortMemberPath ) ;
96- }
97-
98- Dispatcher . BeginInvoke ( ( Action ) ( ( )
99- =>
100- {
101- // call .Clear() on the virtualizingObservableCollection to force a refresh / reset
102- _myDataVirtualizedAsyncFilterSortObservableCollection . Clear ( ) ;
103- } ) ) ;
104-
105- e . Handled = true ;
74+ Debugger . Break ( ) ;
10675 }
10776
108- private Timer _filterTimer ;
109- //static System.Threading.Timer _filterTimer = new System.Threading.Timer( FilterTimerElapsed );
110-
11177 private void FilterTextBox_TextChanged ( object sender , TextChangedEventArgs e )
11278 {
11379 if ( _filterTimer == null )
11480 {
115- _filterTimer = new Timer ( 3000 ) ;
81+ _filterTimer = new Timer ( 1000 ) ;
11682 _filterTimer . Elapsed += FilterTimerElapsed ;
11783 }
11884
@@ -145,10 +111,6 @@ private void FilterTimerElapsed( object sender, ElapsedEventArgs elapsedEventArg
145111 // Notify filter definition update
146112 _filterTimer . Stop ( ) ;
147113
148- //Task<int> task = _myRemoteOrDbDataSourceAsyncProxy.GetCountAsync();
149- //task.Wait();
150- //int aa1 = task.Result;
151-
152114 _myRemoteOrDbDataSourceAsyncProxy . FilterDescriptionList . OnCollectionReset ( ) ;
153115
154116 Dispatcher . BeginInvoke ( ( Action ) ( ( )
@@ -157,29 +119,65 @@ private void FilterTimerElapsed( object sender, ElapsedEventArgs elapsedEventArg
157119 // call .Clear() on the virtualizingObservableCollection to force a refresh / reset
158120 _myDataVirtualizedAsyncFilterSortObservableCollection . Clear ( ) ;
159121 } ) ) ;
160- // BUG bug bizare. Le filter est bien appliqué, le count dans la source est bon mais le count dans la DataGrid (vertical scroll est faut
161- // comme ci la view interne de la DataGrid fichait le bazard
122+ }
123+ catch ( Exception ex )
124+ {
125+ int aa = 0 ;
126+ }
127+ }
162128
129+ private void TstDataGridAsyncFilterSort_Sorting ( object sender , DataGridSortingEventArgs e )
130+ {
131+ DataGrid grid = sender as DataGrid ;
163132
164- //TstDataGridAsyncFilterSort.ItemsSource = null ;
165- //TstDataGridAsyncFilterSort.ItemsSource = MyDataVirtualizedAsyncFilterSortObservableCollection ;
133+ var sortDirection = e . Column . SortDirection ;
134+ string sortMemberPath = e . Column . SortMemberPath ;
166135
167- //task = _myRemoteOrDbDataSourceAsyncProxy.GetCountAsync();
168- //task.Wait();
169- //int aa2 = task.Result;
136+ if ( sortDirection == null )
137+ {
138+ e . Column . SortDirection = ListSortDirection . Ascending ;
139+ _myRemoteOrDbDataSourceAsyncProxy . SortDescriptionList . Add ( new SortDescription ( sortMemberPath , ListSortDirection . Ascending ) ) ;
170140 }
171- catch ( Exception ex )
141+ else if ( sortDirection == ListSortDirection . Ascending )
172142 {
173- int qq = 0 ;
143+ e . Column . SortDirection = ListSortDirection . Descending ;
144+ _myRemoteOrDbDataSourceAsyncProxy . SortDescriptionList . Add ( new SortDescription ( sortMemberPath , ListSortDirection . Descending ) ) ;
145+ }
146+ else if ( sortDirection == ListSortDirection . Descending )
147+ {
148+ e . Column . SortDirection = null ;
149+ _myRemoteOrDbDataSourceAsyncProxy . SortDescriptionList . Remove ( sortMemberPath ) ;
174150 }
151+
152+ Dispatcher . BeginInvoke ( ( Action ) ( ( )
153+ =>
154+ {
155+ // call .Clear() on the virtualizingObservableCollection to force a refresh / reset
156+ _myDataVirtualizedAsyncFilterSortObservableCollection . Clear ( ) ;
157+ } ) ) ;
158+
159+ e . Handled = true ;
175160 }
176161
177- #endregion Asynchrony source filter sort
162+ #endregion
178163
179- private void DbgButton_Click ( object sender , RoutedEventArgs e )
164+ #region properties
165+
166+ public VirtualizingObservableCollection < RemoteOrDbDataItem > MyDataVirtualizedAsyncFilterSortObservableCollection
180167 {
181- //PaginationManager<RemoteOrDbDataItem> aa = MyDataVirtualized.Provider as PaginationManager<RemoteOrDbDataItem>;
182- Debugger . Break ( ) ;
168+ get
169+ {
170+ if ( _myDataVirtualizedAsyncFilterSortObservableCollection == null )
171+ {
172+ _myRemoteOrDbDataSourceAsyncProxy = new RemoteOrDbDataSourceAsyncProxy ( new RemoteOrDbDataSourceEmulation ( ) ) ;
173+ _myDataVirtualizedAsyncFilterSortObservableCollection =
174+ new VirtualizingObservableCollection < RemoteOrDbDataItem > (
175+ new PaginationManager < RemoteOrDbDataItem > ( _myRemoteOrDbDataSourceAsyncProxy ) ) ;
176+ }
177+ return _myDataVirtualizedAsyncFilterSortObservableCollection ;
178+ }
183179 }
180+
181+ #endregion
184182 }
185183}
0 commit comments