繁体   English   中英

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

[英]Which event fires first in Windows Phone 7?

是OnNavigatedTo还是Loaded事件? 我已经可以互换使用两者,但是我想清楚地知道哪一个先出现。

OnNavigatedTo首先触发-来源-一个简单的实验
见下面的代码


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));
        }
    }

在OnNavigatedTo中:

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

已加载:

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

在调试模式下运行,请参阅先写哪个。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM