UWP--页面传值

 

        //匿名对象
        private void Button1_OnClick(object sender, RoutedEventArgs e)
        {
            this.Frame.Navigate(typeof(PageNavigate2), new { id = 1, name = "LBI" });
        }

        //利用反射获取
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            var parameter = e.Parameter;

            var type = e.Parameter?.GetType();
            if (type == null)
            {
                return;
            }

            var id = type.GetProperty("id").GetValue(parameter);
            var name = type.GetProperty("name").GetValue(parameter);

            Debug.WriteLine($"id:{id} name:{name}");
        }

 

你可能感兴趣的:(UWP--页面传值)