从全景页面导航到非全景页面(列表项目)

时间:2013-04-09 17:39:44

标签: c# windows-phone-7

这是我的全景页面项目的xaml。

<controls:PanoramaItem x:Name="deeln" Header="Deelnemers" Style="{StaticResource subtitle}">
                <!--Double line list with image placeholder and text wrapping-->
                <ListBox Margin="12,0,-12,0" ItemsSource="{Binding ItemsDeelnemer}" x:Name="lbDeelnemer" SelectionChanged="lbDeelnemer_SelectionChanged">
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <ScrollViewer HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Disabled">
                                <StackPanel Orientation="Horizontal" Margin="0,0,0,17">
                                    <TextBlock Foreground="Black" TextWrapping="Wrap" Text="{Binding LineNr}" Style="{StaticResource PhoneTextExtraLargeStyle}" ></TextBlock>
                                    <StackPanel Width="430" Height="100">
                                        <TextBlock Foreground="Black" TextWrapping="Wrap" Text="{Binding LineNaamWielrenner1}" Style="{StaticResource PhoneTextExtraLargeStyle}" FontSize="35"></TextBlock>
                                        <TextBlock Foreground="Black" TextWrapping="Wrap" Text="{Binding LineNaamWielrenner2}" Style="{StaticResource PhoneTextExtraLargeStyle}" FontSize="35"></TextBlock>
                                    </StackPanel>
                                </StackPanel>
                            </ScrollViewer>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
            </controls:PanoramaItem>

以下是我在Panorama页面中的代码。

private void lbDeelnemer_SelectionChanged(object sender,SelectionChangedEventArgs e)         {             #region转到特定的deelnemerinfo屏幕

        // If selected index is -1 (no selection) do nothing
        if (lbDeelnemer.SelectedIndex == -1)
            return;

        // Navigate to the new page

        if (lbDeelnemer.SelectedIndex == 0)
        {
            NavigationService.Navigate(new Uri("/DeelnemerInfo.xaml", UriKind.Relative));
            //NavigationService.Navigate(new Uri("/DeelnemerInfo.xaml?selectedItem=" + lbDeelnemer.SelectedIndex, UriKind.Relative));
        }

        // Reset selected index to -1 (no selection)
        lbDeelnemer.SelectedIndex = -1;

        #endregion
    }

以下是非全景页面中的代码。

protected override void OnNavigatedTo(NavigationEventArgs e)         {             //第二次尝试             string strItemIndex;             if(NavigationContext.QueryString.TryGetValue(“goto”,out strItemIndex))                 PanoramaControl.DefaultItem = MyPanorama.Items [Convert.ToInt32(strItemIndex)];

        base.OnNavigatedTo(e);

        //first try
        string selectedIndex = "";
        if (NavigationContext.QueryString.TryGetValue("selectedItem", out selectedIndex))
        {
            int index = int.Parse(selectedIndex);
            DataContext = App.ViewModel.ItemsDeelnemer[index];
        }
    }

我的问题,我想像使用默认的数据绑定应用程序一样导航。您单击第一个listitem,然后转到新页面(非全景)。 它看起来很简单,但我找不到它。

1 个答案:

答案 0 :(得分:0)

尝试将tag属性绑定到index / itemvalue

       <ListBox>
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel>
                        <HyperlinkButton Tag="{Binding FileName}" Click="location_Click"/>
                        <TextBlock Text="{Binding DateCreated}"/>                                       
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>

相应地导航

private void location_Click(object sender, RoutedEventArgs e)
        {
            HyperlinkButton clicked = (HyperlinkButton)sender;
            string uri = "/noteapp;component/ViewEdit.xaml?id=" + clicked.Tag;
            NavigationService.Navigate(new Uri(uri, UriKind.Relative));
        }

在panaroma页面上使用这样的东西来检索值

filename = NavigationContext.QueryString["id"];
var storage = IsolatedStorageFile.GetUserStoreForApplication();
using (var file = storage.OpenFile(filename, FileMode.Open))