c# - OnNavigatedTo 与 Load 事件

标签 c# initialization windows-phone-7

在几个在线示例中,我发现了这一点:

public partial class ForecastPage : PhoneApplicationPage
{
    Forecast forecast;

    public ForecastPage()
    {
        InitializeComponent();
    }

    protected override void OnNavigatedTo(NavigationEventArgs e)
    {
        // code here
    }
}

但在其他人中我发现 Load 事件的用法如下

public partial class Person : PhoneApplicationPage
{
  private PersonViewModel _ViewModel;

  public Person()
  {
     InitializeComponent();
     this.Loaded += new RoutedEventHandler(SearchView_Loaded);
  }

  void SearchView_Loaded(object sender, RoutedEventArgs e)
  {
     // code here
  }
}

我知道 OnNavigatedToLoad 事件之前触发,但两者都在 UI 绘制到手机之前触发,所以我的问题是 有什么优势吗 正在使用另一种方法吗?

最佳答案

我不同意 Tigran。

public View()
{
  InitializeComponent();

  personList.ItemsSource = PersonDataSource.CreateList(100);

    Loaded += (sender, args) => Debug.WriteLine("Loaded");
}

  protected override void OnNavigatedTo(NavigationEventArgs e)
  {
      Debug.WriteLine("Navigated");
  }

向前向后跳时,输出为

Navigated Loaded Navigated Loaded Navigated Loaded

因此,OnNavigated 在页面导航 完成时调用,但在加载页面控件之前(期间)调用,而 Loaded 在以下时间调用页面已准备就绪,所有控件都已加载

关于c# - OnNavigatedTo 与 Load 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9403103/

相关文章:

c# - 下载文件超时

连接来自 char 输入的字符串

c# - "UpdateSourceTrigger=PropertyChanged"相当于 Windows Phone 7 文本框

ios - 在 objective-c 中覆盖和自定义初始化

java - Java中的数组常量初始化

c# - Windows Phone 7 中的媒体播放器

silverlight - 是否为容器启用?

c# - 实现 IEnumerable 问题

c# - .NET:如何检查泛型类中的类型?

c# - DDD 中的每个服务类都有一个接口(interface)是一种好的设计实践吗?