在显示空电话8.1 UAP的页面之间传递数据

时间:2015-08-23 00:53:32

标签: c# xaml windows-phone-8.1

我正在尝试将数据从一个页面传递到另一个页面但由于某种原因它显示为null。我不知道为什么

我正在使用以下技术,如果不是从web服务加载我的数据的最佳方式,我不会这样做。现在te数据在列表中很好,但我想知道我是否没有访问正确的方法来传递数据。

请记住,我的控件是在一个集线器控件内,它在加载的事件中发现它没问题,但是我没有发送者,所以它总是挂起来

private async void grdMovies_Loaded(object sender, RoutedEventArgs e)
{

            ProgressRing pr = new ProgressRing();
            pr.IsActive = true;

           popcornpk_Dal popcorn_dal = new popcornpk_Dal();


          MovieList movieList = await popcorn_dal.GetAllMovies();
         var listView = (ListView)sender;

        listView.ItemsSource = movieList.movie_list ;

        pr.IsActive = false;

}



private void moveListView_Tapped(object sender, TappedRoutedEventArgs e)

{

          MovieList moveInfoSelected = listMovies.SelectedItem as MovieList;

            Frame.Navigate(typeof(movieInfo), moveInfoSelected);

}

我的Xaml供参考

<HubSection x:Name="hubSectionMovies" x:Uid="hubSectionMovies" Header="Movies" Width="Auto"
                     DataContext="{Binding Groups[0]}" HeaderTemplate="{ThemeResource HubSectionHeaderTemplate}">
            <DataTemplate>
                <ListView x:Name="moveiListView"
                    ItemsSource="{Binding}"
                    IsItemClickEnabled="True"
                    Loaded="grdMovies_Loaded"
                    ContinuumNavigationTransitionInfo.ExitElementContainer="True"   SelectionChanged="moveListView_SelectionChanged" Tapped="moveListView_Tapped_1" >

                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto"/>
                                    <ColumnDefinition Width="*"/>
                                </Grid.ColumnDefinitions>

                                <Border Background="{ThemeResource ListViewItemPlaceholderBackgroundThemeBrush}" Margin="0,9.5,0,0" Grid.Column="0" HorizontalAlignment="Left">
                                    <Image Source="{Binding image}" Width="160" Height="234" Stretch="UniformToFill" AutomationProperties.Name="{Binding Title}" />
                                </Border>
                                <StackPanel Grid.Column="1" Margin="14.5,0,0,0">
                                    <TextBlock Text="{Binding name}" Style="{ThemeResource ListViewItemTextBlockStyle}"/>
                                </StackPanel>
                            </Grid>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>

            </DataTemplate>
        </HubSection>

为了完整性,我在下面附上我的评论

public class Movie
     {
        public string id { get; set; }
        public string name { get; set; }
        public string description { get; set; }
        public string image { get; set; }
        public string secondry_images { get; set; }
        public string actor { get; set; }
        public string actoress { get; set; }
        public string director { get; set; }
        public string music_director { get; set; }
        public string release_date { get; set; }
        public string tags { get; set; }
        public string age_restriction { get; set; }
        public string box_office { get; set; }
        public string official_site { get; set; }
        public string duration { get; set; }
        public string writers { get; set; }
        public int imdb { get; set; }
        public string status { get; set; }
        public string language { get; set; }
        public string created { get; set; }
        public string modified { get; set; }
        public string movie_category_id { get; set; }
        public string slug { get; set; }
        public string movie_show_time_id { get; set; }
        public string theatre_movie_screen_id { get; set; }
        public string videous { get; set; }
        public string videos { get; set; }
        public string comming_soon { get; set; }
        public string avg { get; set; }
     }

     public class MovieList
     {
        public List<Movie> movie_list { get; set; }
     }

1 个答案:

答案 0 :(得分:0)

该行:

MovieList moveInfoSelected = listMovies.SelectedItem as MovieList;
moveListView_Tapped中的

始终为null,因为SelectedItem的类型为Movie

为了使其成功,你需要施放到Movie

Movie moveInfoSelected = moveiListView.SelectedItem as Movie;

并确保在Movie页面中处理movieInfo类型。

修改

首先,您需要从XAML 删除 IsItemClickEnabled="True"或将其设置为False。 然后,您需要将导航代码放在SelectionChanged处理程序中,在您的方法中moveListView_SelectionChanged

private void moveListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        var listView = sender as ListView;
        Movie moveInfoSelected = listView.SelectedItem as Movie;
        Frame.Navigate(typeof(movieInfo), moveInfoSelected);
    }