@@ -170,7 +170,7 @@ public static bool GetIsNullOrEmpty(DependencyObject element)
170
170
/// Framework use only.
171
171
/// </summary>
172
172
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 ) ) ;
174
174
175
175
176
176
/// <summary>
@@ -264,34 +264,41 @@ private static void TextPropertyChangedCallback(DependencyObject dependencyObjec
264
264
265
265
private static void ManagedPropertyChangedCallback ( DependencyObject dependencyObject , DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs )
266
266
{
267
- var textBox = dependencyPropertyChangedEventArgs . OldValue as TextBox ;
268
- if ( textBox != null )
267
+ var control = dependencyPropertyChangedEventArgs . OldValue as Control ;
268
+ if ( control != null )
269
269
{
270
- textBox . IsVisibleChanged -= ManagedTextBoxOnIsVisibleChanged ;
270
+ control . IsVisibleChanged -= ManagedTextBoxOnIsVisibleChanged ;
271
271
}
272
272
273
- textBox = dependencyPropertyChangedEventArgs . NewValue as TextBox ;
274
- if ( textBox != null )
273
+ control = dependencyPropertyChangedEventArgs . NewValue as Control ;
274
+ if ( control != null )
275
275
{
276
- textBox . IsVisibleChanged += ManagedTextBoxOnIsVisibleChanged ;
276
+ control . IsVisibleChanged += ManagedTextBoxOnIsVisibleChanged ;
277
277
}
278
278
}
279
279
280
280
private static void ManagedTextBoxOnIsVisibleChanged ( object sender , DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs )
281
281
{
282
- var textBox = ( TextBox ) sender ;
282
+ if ( ! RefreshState ( sender as TextBox , textBox => textBox . Text ) )
283
+ RefreshState ( sender as ComboBox , comboBox => comboBox . Text ) ;
284
+ }
283
285
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 ;
285
290
286
- var state = string . IsNullOrEmpty ( textBox . Text )
291
+ var state = string . IsNullOrEmpty ( textAccessor ( control ) )
287
292
? "MaterialDesignStateTextEmpty"
288
293
: "MaterialDesignStateTextNotEmpty" ;
289
294
290
295
//yep, had to invoke post this to trigger refresh
291
- textBox . Dispatcher . BeginInvoke ( new Action ( ( ) =>
296
+ control . Dispatcher . BeginInvoke ( new Action ( ( ) =>
292
297
{
293
- VisualStateManager . GoToState ( textBox , state , false ) ;
298
+ VisualStateManager . GoToState ( control , state , false ) ;
294
299
} ) ) ;
300
+
301
+ return true ;
295
302
}
296
303
297
304
#endregion
0 commit comments