@@ -25,8 +25,8 @@ public class NavigationViewModel : ViewModelBase, INavigationViewModel
2525 public NavigationViewModel ( )
2626 {
2727 history = new ReactiveList < IPanePageViewModel > ( ) ;
28- history . BeforeItemsAdded . Subscribe ( BeforeItemAdded ) ;
29- history . CollectionChanged += CollectionChanged ;
28+ history . Changing . Subscribe ( CollectionChanging ) ;
29+ history . Changed . Subscribe ( CollectionChanged ) ;
3030
3131 var pos = this . WhenAnyValue (
3232 x => x . Index ,
@@ -107,7 +107,7 @@ public bool Forward()
107107 public void Clear ( )
108108 {
109109 Index = - 1 ;
110- history . RemoveRange ( 0 , history . Count ) ;
110+ history . Clear ( ) ;
111111 }
112112
113113 public int RemoveAll ( IPanePageViewModel page )
@@ -139,27 +139,34 @@ void ItemRemoved(int removedIndex, IPanePageViewModel page)
139139 }
140140 }
141141
142- void CollectionChanged ( object sender , NotifyCollectionChangedEventArgs e )
142+ void CollectionChanging ( NotifyCollectionChangedEventArgs e )
143143 {
144- using ( DelayChangeNotifications ( ) )
144+ if ( e . Action == NotifyCollectionChangedAction . Add )
145145 {
146- switch ( e . Action )
146+ foreach ( IPanePageViewModel page in e . NewItems )
147147 {
148- case NotifyCollectionChangedAction . Add :
149- break ;
150-
151- case NotifyCollectionChangedAction . Remove :
152- for ( var i = 0 ; i < e . OldItems . Count ; ++ i )
153- {
154- ItemRemoved ( e . OldStartingIndex + i , ( IPanePageViewModel ) e . OldItems [ i ] ) ;
155- }
156- break ;
157-
158- case NotifyCollectionChangedAction . Reset :
159- throw new NotSupportedException ( ) ;
148+ BeforeItemAdded ( page ) ;
149+ }
150+ }
151+ else if ( e . Action == NotifyCollectionChangedAction . Reset )
152+ {
153+ foreach ( var page in history )
154+ {
155+ page . Dispose ( ) ;
156+ }
157+ }
158+ }
160159
161- default :
162- throw new NotImplementedException ( ) ;
160+ void CollectionChanged ( NotifyCollectionChangedEventArgs e )
161+ {
162+ using ( DelayChangeNotifications ( ) )
163+ {
164+ if ( e . Action == NotifyCollectionChangedAction . Remove )
165+ {
166+ for ( var i = 0 ; i < e . OldItems . Count ; ++ i )
167+ {
168+ ItemRemoved ( e . OldStartingIndex + i , ( IPanePageViewModel ) e . OldItems [ i ] ) ;
169+ }
163170 }
164171 }
165172 }
0 commit comments