开发者

How to determine when a WPF User Control has completed loading

开发者 https://www.devze.com 2023-03-22 23:45 出处:网络
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 loadin开发者_如何学G

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 loadin开发者_如何学Gog. 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.


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


Maybe I misunderstood the problem, but registering for Initialized / Loaded on the UserControl does not do the trick? If not, how do you populate the Grid?

0

精彩评论

暂无评论...
验证码 换一张
取 消