WPF页的NavigationService - 如何加载UI执行的页事件之前,完全加载、事件、WPF、NavigationService

2023-09-06 16:57:32 作者:既不爱,就滚开

我有使用WPF +页面导航的应用程序。应用程序和流程工作正常,而不是一个问题。但最近,同时做一些测试,我发现在code以下行为。

我已经使用 NavigationServices.Navigate(新类());

当我触发此功能的页面不被正确导航,但它甚至在完全载入页面执行某些事件。

例如:

在类的构造函数,非常下一行的InitializeComponent(); 已启用了一个单选按钮,这单选按钮活动托运启用。因此,基于这个逻辑被执行第一用户界面被完全装载在该帧之前

我的问题是:我该如何停止所有的时间段发生的事件,并确保用户界面载入中,然后将事件触发式

解决方案

使用的 Window.Loaded 事件;该火灾一旦所有UI组件都准备好了。

  

在元素已布局,已呈现且可用于交互时发生。

 公共mywindow的()
{
    的InitializeComponent();
    this.Loaded + = MyWindow_Loaded;
}

私人无效MainWindow_Loaded(对象发件人,RoutedEventArgs E)
{
    //初始化的东西...
}
 
3DMAX加载自定义UI方案不能变成黑色

I have an application which uses WPF + Page Navigation. The application and the flow is working fine and not an issue. But recently, while doing some tests, I found the following behaviour in the code.

I have used NavigationServices.Navigate(new Class());

When I trigger this function the page does gets navigated properly, but it executes certain events even before loading the page completely.

Example:

Under the class constructor and very next line after InitializeComponent(); I have enabled an radioButton and this radioButton has event checked enabled. So based on this the logic is executed first even before the UI is loaded completely in the frame.

My question: How do I stop all the events for time period and make sure the UI is loaded completely and then the events fires-up.

解决方案

Use the Window.Loaded event; that fires once all UI components are ready.

Occurs when the element is laid out, rendered, and ready for interaction.

public MyWindow() 
{
    InitializeComponent();
    this.Loaded += MyWindow_Loaded;
}

private void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
    // initialization stuff ...
}