如何确定WPF用户控件何时完成加载(How to determine when a WPF User Control has completed loading)

编程入门 行业动态 更新时间:2024-10-15 20:17:21
如何确定WPF用户控件何时完成加载(How to determine when a WPF User Control has completed loading)

我有一个带有UIElement Grid的WPF用户控件,里面有几个文本框和组合框。 我有一个Button(btnApply),当表单加载完成后,其IsEnabled状态应为false。 但是,在填充网格时会触发TextChanged事件,并将IsEnabled更改为true。 我添加了一个布尔方法,在用户控件完成加载后保持btnApply.IsEnabled = false。 但是,我无法分辨用户控件何时完全加载以改变我的方法的布尔状态以允许更改btnApply.IsEnabled。 我已经在用户控件上尝试了Loaded事件并尝试检查IsLoaded事件,并且在用户控件上的所有元素完成加载之前它们都被触发了。

编辑:用户控件的UIElement网格通过ItemsSource = List填充。 通过TextChanged和SelectionChanged事件捕获文本框和组合框更改。

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.

最满意答案

尝试使用Dispatcher在稍后的DispatcherPriority而不是Loaded上触发IsEnabled更改,例如Input。

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

您可以在此处查看DispatcherPriority订单

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

更多推荐

IsEnabled,btnApply,用户,User,电脑培训,计算机培训,IT培训"/> <meta name="de

本文发布于:2023-08-07 06:50:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1462860.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:控件   加载   用户   WPF   determine

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!