I am trying to pass data from one page to another but for some reason it is showing up null. I dont no why
I am using the following technique i dont no if its the best way or not to load my data in from a webservice. Now te data is their in the list fine but I am wondering if i not accessing the correct method on tap to pass the data.
Please bare in mind that my control is within a hub control it finding it fine with the loaded event but obv i dont have the sender from that so its always comming up null
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);
}
My Xaml For Reference
<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>
I enclose my calss below for completeness
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; }
}
The line:
MovieList moveInfoSelected = listMovies.SelectedItem as MovieList;
in moveListView_Tapped
will always be null
because the SelectedItem
will be of type Movie
.
To make it work you need to cast is to Movie
:
Movie moveInfoSelected = moveiListView.SelectedItem as Movie;
And make sure you handle Movie
types in your movieInfo
page.
EDIT:
First you need to remove the IsItemClickEnabled="True"
from your XAML or set it to False
. Then you need to put your navigation code in the SelectionChanged
handler, in your case in the method 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);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.