Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine when a WPF User Control has completed loading

Tags:

c#

.net-3.5

wpf

I have a WPF User Control with a UIElement Grid with several text boxes and combo boxes. I have a Button(btnApply) whose IsEnabled state should be false when the form has finished loading. However, the TextChanged event is being fired as the grid is being populated and changes the IsEnabled to true. I've added a boolean method that does keep the btnApply.IsEnabled = false after the user control has completed loading. But, I can't tell when the User Control has fully completed loading to alter the boolean state of my method to allow the btnApply.IsEnabled to be altered. I've tried Loaded events on the User Control and tried checking the IsLoaded event and they are all fired before all the elements on the User Control have finished loading.

Edit: The User Control's UIElement Grid is populated via ItemsSource = List. The text box and combo box changes are trapped via TextChanged and SelectionChanged events.

like image 988
GAR8 Avatar asked Jul 25 '11 18:07

GAR8


1 Answers

Try using the Dispatcher to fire the IsEnabled change at a later DispatcherPriority than Loaded, such as Input.

Dispatcher.BeginInvoke(DispatcherPriority.Input,
    new Action(delegate() { btnApply.IsEnabled = false; } ));

You can view the DispatcherPriority order here

like image 166
Rachel Avatar answered Oct 10 '22 02:10

Rachel