33// See the LICENSE file in the project root for more information.
44
55using System ;
6+ using System . Collections . ObjectModel ;
67using System . Linq ;
78using Microsoft . Toolkit . Uwp . SampleApp . Data ;
89using Microsoft . Toolkit . Uwp . UI . Controls ;
910using Microsoft . Toolkit . Uwp . UI . Extensions ;
1011using Windows . UI . Popups ;
1112using Windows . UI . Xaml ;
13+ using Windows . UI . Xaml . Controls . Primitives ;
1214
1315namespace Microsoft . Toolkit . Uwp . SampleApp . SamplePages
1416{
1517 public sealed partial class AdaptiveGridViewPage : IXamlRenderListener
1618 {
17- private AdaptiveGridView adaptiveGridViewControl ;
19+ private AdaptiveGridView _adaptiveGridViewControl ;
20+ private PhotoDataItem [ ] _originalPhotos ;
21+ private ObservableCollection < PhotoDataItem > _boundPhotos ;
1822
1923 public AdaptiveGridViewPage ( )
2024 {
@@ -23,19 +27,46 @@ public AdaptiveGridViewPage()
2327
2428 public async void OnXamlRendered ( FrameworkElement control )
2529 {
26- adaptiveGridViewControl = control . FindDescendantByName ( "AdaptiveGridViewcontrol" ) as AdaptiveGridView ;
27- if ( adaptiveGridViewControl != null )
30+ _adaptiveGridViewControl = control . FindDescendantByName ( "AdaptiveGridViewcontrol" ) as AdaptiveGridView ;
31+ if ( _adaptiveGridViewControl != null )
2832 {
29- adaptiveGridViewControl . ItemsSource = await new Data . PhotosDataSource ( ) . GetItemsAsync ( ) ;
30- adaptiveGridViewControl . ItemClick += AdaptiveGridViewControl_ItemClick ;
31- adaptiveGridViewControl . SelectionChanged += AdaptiveGridViewControl_SelectionChanged ;
33+ var allPhotos = await new Data . PhotosDataSource ( ) . GetItemsAsync ( ) ;
34+ _originalPhotos = allPhotos . ToArray ( ) ;
35+ _boundPhotos = new ObservableCollection < PhotoDataItem > ( _originalPhotos ) ;
36+ _adaptiveGridViewControl . ItemsSource = _boundPhotos ;
37+ _adaptiveGridViewControl . ItemClick += AdaptiveGridViewControl_ItemClick ;
38+ _adaptiveGridViewControl . SelectionChanged += AdaptiveGridViewControl_SelectionChanged ;
39+ NumberSlider . Minimum = 1 ;
40+ NumberSlider . Maximum = _originalPhotos . Length ;
41+ NumberSlider . Value = _originalPhotos . Length ;
42+ NumberSlider . ValueChanged += OnNumberSliderValueChanged ;
43+ }
44+ }
45+
46+ private void OnNumberSliderValueChanged ( object sender , RangeBaseValueChangedEventArgs e )
47+ {
48+ var newCount = ( int ) e . NewValue ;
49+ var currentCount = _boundPhotos . Count ;
50+ if ( currentCount < newCount )
51+ {
52+ for ( var i = currentCount ; i < newCount ; i ++ )
53+ {
54+ _boundPhotos . Add ( _originalPhotos [ i ] ) ;
55+ }
56+ }
57+ else if ( currentCount > newCount )
58+ {
59+ for ( var i = currentCount ; i > newCount ; i -- )
60+ {
61+ _boundPhotos . Remove ( _originalPhotos [ i - 1 ] ) ;
62+ }
3263 }
3364 }
3465
3566 private void AdaptiveGridViewControl_SelectionChanged ( object sender , Windows . UI . Xaml . Controls . SelectionChangedEventArgs e )
3667 {
37- SelectedItemCountTextBlock . Text = adaptiveGridViewControl . SelectedItems . Any ( )
38- ? $ "You have selected { adaptiveGridViewControl . SelectedItems . Count } items."
68+ SelectedItemCountTextBlock . Text = _adaptiveGridViewControl . SelectedItems . Any ( )
69+ ? $ "You have selected { _adaptiveGridViewControl . SelectedItems . Count } items."
3970 : "You haven't selected any items" ;
4071 }
4172
0 commit comments