WPF页的NavigationService - 如何加载UI执行的页事件之前,完全 [英] WPF Page NavigationService - How to load UI Completely before executing Page Events

查看:973
本文介绍了WPF页的NavigationService - 如何加载UI执行的页事件之前,完全的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

例如:

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

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

解决方案

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

  

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

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

私人无效MainWindow_Loaded(对象发件人,RoutedEventArgs E)
{
    //初始化的东西...
}
 

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 ...
}

这篇关于WPF页的NavigationService - 如何加载UI执行的页事件之前,完全的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆