@@ -9,43 +9,55 @@ class NewsPage : BaseContentPage<NewsViewModel>
9
9
readonly IDispatcher _dispatcher ;
10
10
11
11
public NewsPage ( IBrowser browser ,
12
- IDispatcher dispatcher ,
13
- NewsViewModel newsViewModel ) : base ( newsViewModel , "Top Stories" )
12
+ IDispatcher dispatcher ,
13
+ NewsViewModel newsViewModel ) : base ( newsViewModel , "Top Stories" )
14
14
{
15
15
_browser = browser ;
16
16
_dispatcher = dispatcher ;
17
17
18
18
BindingContext . PullToRefreshFailed += HandlePullToRefreshFailed ;
19
19
20
20
Content = new RefreshView
21
- {
22
- RefreshColor = Colors . Black ,
23
-
24
- Content = new CollectionView
25
21
{
26
- BackgroundColor = Color . FromArgb ( "F6F6EF" ) ,
27
- SelectionMode = SelectionMode . Single ,
28
- ItemTemplate = new StoryDataTemplate ( ) ,
29
-
30
- } . Bind ( CollectionView . ItemsSourceProperty , static ( NewsViewModel vm ) => vm . TopStoryCollection )
31
- . Invoke ( collectionView => collectionView . SelectionChanged += HandleSelectionChanged )
32
-
33
- } . Bind ( RefreshView . IsRefreshingProperty , static ( NewsViewModel vm ) => vm . IsListRefreshing )
34
- . Bind ( RefreshView . CommandProperty , static ( NewsViewModel vm ) => vm . RefreshCommand ) ;
22
+ RefreshColor = Colors . Black ,
23
+
24
+ Content = new CollectionView
25
+ {
26
+ BackgroundColor = Color . FromArgb ( "F6F6EF" ) ,
27
+ SelectionMode = SelectionMode . Single ,
28
+ ItemTemplate = new StoryDataTemplate ( ) ,
29
+
30
+ } . Bind ( CollectionView . ItemsSourceProperty ,
31
+ getter : static ( NewsViewModel vm ) => vm . TopStoryCollection )
32
+ . Invoke ( collectionView => collectionView . SelectionChanged += HandleSelectionChanged )
33
+
34
+ } . Bind ( RefreshView . IsRefreshingProperty ,
35
+ getter : static ( NewsViewModel vm ) => vm . IsListRefreshing ,
36
+ setter : static ( vm , isRefreshing ) => vm . IsListRefreshing = isRefreshing )
37
+ . Bind ( RefreshView . CommandProperty ,
38
+ getter : static ( NewsViewModel vm ) => vm . RefreshCommand ,
39
+ mode : BindingMode . OneTime ) ;
35
40
}
36
41
37
42
protected override void OnAppearing ( )
38
43
{
39
44
base . OnAppearing ( ) ;
40
45
41
- if ( Content is RefreshView refreshView
42
- && refreshView . Content is CollectionView collectionView
46
+ if ( Content is RefreshView { Content : CollectionView collectionView } refreshView
43
47
&& IsNullOrEmpty ( collectionView . ItemsSource ) )
44
48
{
45
49
refreshView . IsRefreshing = true ;
46
50
}
47
51
48
- static bool IsNullOrEmpty ( in IEnumerable ? enumerable ) => ! enumerable ? . GetEnumerator ( ) . MoveNext ( ) ?? true ;
52
+ static bool IsNullOrEmpty ( in IEnumerable ? enumerable )
53
+ {
54
+ if ( enumerable is null )
55
+ return false ;
56
+
57
+ var enumerator = enumerable . GetEnumerator ( ) ?? throw new InvalidOperationException ( "Enumerator not found" ) ;
58
+ using var disposable = ( IDisposable ) enumerator ;
59
+ return ! enumerator . MoveNext ( ) ;
60
+ }
49
61
}
50
62
51
63
async void HandleSelectionChanged ( object ? sender , SelectionChangedEventArgs e )
0 commit comments