@@ -170,7 +170,7 @@ public static bool GetIsNullOrEmpty(DependencyObject element)
170170 /// Framework use only.
171171 /// </summary>
172172 public static readonly DependencyProperty ManagedProperty = DependencyProperty . RegisterAttached (
173- "Managed" , typeof ( TextBox ) , typeof ( TextFieldAssist ) , new PropertyMetadata ( default ( TextBox ) , ManagedPropertyChangedCallback ) ) ;
173+ "Managed" , typeof ( Control ) , typeof ( TextFieldAssist ) , new PropertyMetadata ( default ( Control ) , ManagedPropertyChangedCallback ) ) ;
174174
175175
176176 /// <summary>
@@ -264,34 +264,41 @@ private static void TextPropertyChangedCallback(DependencyObject dependencyObjec
264264
265265 private static void ManagedPropertyChangedCallback ( DependencyObject dependencyObject , DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs )
266266 {
267- var textBox = dependencyPropertyChangedEventArgs . OldValue as TextBox ;
268- if ( textBox != null )
267+ var control = dependencyPropertyChangedEventArgs . OldValue as Control ;
268+ if ( control != null )
269269 {
270- textBox . IsVisibleChanged -= ManagedTextBoxOnIsVisibleChanged ;
270+ control . IsVisibleChanged -= ManagedTextBoxOnIsVisibleChanged ;
271271 }
272272
273- textBox = dependencyPropertyChangedEventArgs . NewValue as TextBox ;
274- if ( textBox != null )
273+ control = dependencyPropertyChangedEventArgs . NewValue as Control ;
274+ if ( control != null )
275275 {
276- textBox . IsVisibleChanged += ManagedTextBoxOnIsVisibleChanged ;
276+ control . IsVisibleChanged += ManagedTextBoxOnIsVisibleChanged ;
277277 }
278278 }
279279
280280 private static void ManagedTextBoxOnIsVisibleChanged ( object sender , DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs )
281281 {
282- var textBox = ( TextBox ) sender ;
282+ if ( ! RefreshState ( sender as TextBox , textBox => textBox . Text ) )
283+ RefreshState ( sender as ComboBox , comboBox => comboBox . Text ) ;
284+ }
283285
284- if ( ! textBox . IsVisible ) return ;
286+ private static bool RefreshState < TControl > ( TControl control , Func < TControl , string > textAccessor ) where TControl : Control
287+ {
288+ if ( control == null ) return false ;
289+ if ( ! control . IsVisible ) return true ;
285290
286- var state = string . IsNullOrEmpty ( textBox . Text )
291+ var state = string . IsNullOrEmpty ( textAccessor ( control ) )
287292 ? "MaterialDesignStateTextEmpty"
288293 : "MaterialDesignStateTextNotEmpty" ;
289294
290295 //yep, had to invoke post this to trigger refresh
291- textBox . Dispatcher . BeginInvoke ( new Action ( ( ) =>
296+ control . Dispatcher . BeginInvoke ( new Action ( ( ) =>
292297 {
293- VisualStateManager . GoToState ( textBox , state , false ) ;
298+ VisualStateManager . GoToState ( control , state , false ) ;
294299 } ) ) ;
300+
301+ return true ;
295302 }
296303
297304 #endregion
0 commit comments