积极答复者
页面导航传参问题

问题
答案
全部回复
-
按你提供的第三种方法进行共享数据发现不行;
在MainPivotPage中触发listbox的select 事件进行页面跳转到PropertyDetailPage页面;
在MainpivotPage中定义了
public MainViewModel vm;
public MainPivotPage()
{
InitializeComponent();
vm = new MainViewModel();
PropertyList.Loaded +=new RoutedEventHandler(PropertyList_Loaded);
PropertyList.PropertyListBox.SelectionChanged +=new SelectionChangedEventHandler(PropertyListBox_SelectionChanged);
CommunityList.Loaded +=new RoutedEventHandler(CommunityList_Loaded);
CommunityList.CommunityListBox.SelectionChanged += new SelectionChangedEventHandler(CommunityListBox_SelectionChanged);
}NavigationService.Navigate(new Uri("/PropertyDetailPage.xaml?item="+((ListBox)sender).SelectedIndex.ToString(), UriKind.Relative));
在PropertyDetailPage重写了
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
if (e.Content is MainPivotPage)
{
vm = (e.Content as MainPivotPage).vm.Properties[int.Parse(NavigationContext.QueryString["item"])];
DataContext = vm;
}
}if语句中根本都不走的,查看e.Content是PropertyDetailPage
我的使用哪里有错吗?