Windows phone 7 Can';t访问2+;数据绑定枢轴的子级
好的,这是我在这里的第一篇帖子,所以我不确定我需要多详细,我也不是最擅长描述事情的人,但我会尝试一下 因此,在我的应用程序主页上,当用户单击文本块时,它会将其发送到下一个页面,即动态透视页面:Windows phone 7 Can';t访问2+;数据绑定枢轴的子级,windows-phone-7,Windows Phone 7,好的,这是我在这里的第一篇帖子,所以我不确定我需要多详细,我也不是最擅长描述事情的人,但我会尝试一下 因此,在我的应用程序主页上,当用户单击文本块时,它会将其发送到下一个页面,即动态透视页面: <Grid x:Name="LayoutRoot" Background="Transparent" DataContext="{Binding Products}"> <!--Pivot Control--> <controls:Pivot x:Name="
<Grid x:Name="LayoutRoot" Background="Transparent" DataContext="{Binding Products}">
<!--Pivot Control-->
<controls:Pivot x:Name="Pivot" Title="{Binding name}" ItemsSource="{Binding pivots}">
<controls:Pivot.HeaderTemplate>
<DataTemplate>
<TextBlock Text="{Binding title}" />
</DataTemplate>
</controls:Pivot.HeaderTemplate>
<controls:Pivot.ItemTemplate>
<DataTemplate>
<ListBox Margin="0,0,-12,0" ItemsSource="{Binding partners}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Margin="0,0,0,17" Width="432" Height="58">
<TextBlock Text="{Binding name}" TextWrapping="Wrap" Tap="showDetails" Style="{StaticResource PhoneTextExtraLargeStyle}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</DataTemplate>
</controls:Pivot.ItemTemplate>
</controls:Pivot>
</Grid>
它传递一个参数,该参数指定应在页面上使用的DataContext以及应选择的pivot。在导航时,它会解析这些参数:
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) {
base.OnNavigatedTo(e);
string selectedType = this.NavigationContext.QueryString["type"];
string selectedPivot = this.NavigationContext.QueryString["pivot"];
int selectedIndex = 0;
switch (selectedType) {
case "product":
LayoutRoot.DataContext = App.ViewModel.Products;
selectedIndex = Array.IndexOf(App.ViewModel.ProductTypes, selectedPivot);
break;
case "service":
LayoutRoot.DataContext = App.ViewModel.Services;
selectedIndex = Array.IndexOf(App.ViewModel.ServiceTypes, selectedPivot);
break;
default:
LayoutRoot.DataContext = App.ViewModel.Products;
break;
}
Pivot.SelectedIndex = selectedIndex;
PivotItem pivotItem = Pivot.ItemContainerGenerator.ContainerFromItem(Pivot.SelectedItem) as PivotItem;
this.selectedList = FindFirstElementInVisualTree<ListBox>(pivotItem);
}
受保护的覆盖无效OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e){
基地。导航到(e);
string selectedType=this.NavigationContext.QueryString[“type”];
string selectedPivot=this.NavigationContext.QueryString[“pivot”];
int selectedIndex=0;
开关(选择类型){
案例“产品”:
LayoutRoot.DataContext=App.ViewModel.Products;
selectedIndex=Array.IndexOf(App.ViewModel.ProductTypes,selectedPivot);
打破
案例“服务”:
LayoutRoot.DataContext=App.ViewModel.Services;
selectedIndex=Array.IndexOf(App.ViewModel.ServiceTypes,selectedPivot);
打破
违约:
LayoutRoot.DataContext=App.ViewModel.Products;
打破
}
Pivot.SelectedIndex=SelectedIndex;
PivotItem PivotItem=Pivot.ItemContainerGenerator.ContainerFromItem(Pivot.SelectedItem)作为PivotItem;
this.selectedList=FindFirstElementVisualTree(数据透视项);
}
这是从哪里来的
所以我的问题是:
当我选择第一个数据集和第一个数据透视时,这一切都可以正常工作,否则它表示数据透视项没有任何子项并抛出错误
你知道我能做些什么吗?也许我完全错了。如果您需要更多详细信息,请告诉我。Pivot控件延迟加载PivotItems,直到实际需要它们为止-它仅加载当前数据透视项及其前后的数据透视项。当用户导航到下一个数据透视项时,您将看到创建的数据透视项
这也会在删除后尝试将用户恢复到上一个数据透视项时表现出来,如果尝试恢复到第三个数据透视项,则会失败。通读本文。我似乎没有刚才提到的问题。我可以选择数据透视项,而不是上一个或下一个数据透视项。我看了一下周围的工作,但看不出它是如何应用的。