哪个事件在Windows Phone 7中首先触发?

时间:2011-10-11 21:30:52

标签: c# silverlight windows-phone-7

是OnNavigatedTo还是Loaded事件?我已经能够互换使用,但我想明确知道哪个是第一个。

2 个答案:

答案 0 :(得分:5)

OnNavigatedTo fires first - source - 一个简单的实验
见下面的代码


public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();
            Loaded += new RoutedEventHandler(MainPage_Loaded);
        }

        void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            throw new NotImplementedException();
        }
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
        }
        // Simple button Click event handler to take us to the second page
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri("/GamePage.xaml", UriKind.Relative));
        }
    }

答案 1 :(得分:2)

OnNavigatedTo中的

System.Diagnostics.Debug.WriteLine("in OnNavigatedTo");

in Loaded:

System.Diagnostics.Debug.WriteLine("in Loaded");

在调试模式下运行,查看哪一个先写入。

相关问题