I have these classes:
public class MovieExt
{
public string Title { get; set; }
public string Year { get; set; }
public List<string> Genres { get; set; }
public List<Actor> Actors { get; set; }
....
}
public class Actor
{
public string Name { get; set; }
public string Birth { get; set; }
public string Biography { get; set; }
public string Url { get; set; }
}
and this is my method in my page:
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
object obj;
if (PhoneApplicationService.Current.State.TryGetValue("movie", out obj))
{
MovieExt movie = (MovieExt)obj;
this.DataContext = movie;
this.imgPoster.Source = new BitmapImage(new Uri(movie.PosterUrl, UriKind.Absolute));
}
base.OnNavigatedTo(e);
}
and in page I am binding properties like this:
<ListBox Grid.Row="4" Grid.Column="1"
Margin="5,5,5,5"
ItemsSource="{Binding Path=Actors }"
x:Name="listStars"/>
For everything it´s working (genres and others). Everything else is string. But for actors I want to bind in list name and after clicking on the actor I want to go to url. How can I bind name property from actor? Thanks
First of all, you need to create
OnSelectedItemChangedevent on yourListBoxto handle clicks on yourActors.Then you need to get your clicked item. You can do this in several ways. The simplest way is
listBox.SelectedItemproperty.And then your can get your Url with
(listBox.SelectedItem as Actor).UrlAlso, when you go back from details page,
SelectedItemwill be not null and click on the same item not fired event in second time. So, setSelectedItemto null when click is handledUPD: to properly bind
Actorclass toListBoxyou need to createItemTemplate: