@@ -89,17 +89,26 @@ public FrameworkElement TargetObject
8989 /// <param name="e">The <see cref="DependencyPropertyChangedEventArgs"/> instance containing the event data.</param>
9090 protected static void OnStateObservableChanged ( DependencyObject sender , DependencyPropertyChangedEventArgs e )
9191 {
92- var @this = ( FollowObservableStateBehavior ) sender ;
93- if ( @this . _watcher != null )
92+ if ( e == null )
9493 {
95- @this . _watcher . Dispose ( ) ;
96- @this . _watcher = null ;
94+ throw new ArgumentNullException ( nameof ( e ) ) ;
9795 }
9896
99- @this . _watcher = ( ( IObservable < string > ) e . NewValue ) . ObserveOn ( RxApp . MainThreadScheduler ) . Subscribe (
97+ if ( ! ( sender is FollowObservableStateBehavior item ) )
98+ {
99+ throw new ArgumentException ( "Sender must be of type " + nameof ( FollowObservableStateBehavior ) , nameof ( sender ) ) ;
100+ }
101+
102+ if ( item . _watcher != null )
103+ {
104+ item . _watcher . Dispose ( ) ;
105+ item . _watcher = null ;
106+ }
107+
108+ item . _watcher = ( ( IObservable < string > ) e . NewValue ) . ObserveOn ( RxApp . MainThreadScheduler ) . Subscribe (
100109 x =>
101110 {
102- var target = @this . TargetObject ?? @this . AssociatedObject ;
111+ var target = item . TargetObject ?? item . AssociatedObject ;
103112#if NETFX_CORE
104113 VisualStateManager . GoToState ( target , x , true ) ;
105114#else
@@ -115,12 +124,12 @@ protected static void OnStateObservableChanged(DependencyObject sender, Dependen
115124 } ,
116125 ex =>
117126 {
118- if ( ! @this . AutoResubscribeOnError )
127+ if ( ! item . AutoResubscribeOnError )
119128 {
120129 return ;
121130 }
122131
123- OnStateObservableChanged ( @this , e ) ;
132+ OnStateObservableChanged ( item , e ) ;
124133 } ) ;
125134 }
126135
0 commit comments