DataBinding是一个二度子类

时间:2013-10-08 03:06:42

标签: c# data-binding mvvm windows-store-apps

我需要帮助绑定数据,特别是如果根数据源对象有许多子类,并且那些子类也有子类。这是我的DataModel:

public class NowShowingMovies
{
  public ObservableCollection<Movie> MovieCollection { get; set; }
  public string Status { get; set; }
  public string Total{ get; set; }
}
public class Movie
{
  public string Id {get;set;}
  public string Title {get;set}
  public UserRating Rating {get;set;}
}
public class UserRating
{
  public string UserRatingURL {get;set;}
}

我的XAML代码是:

<GridView ItemsSource="{Binding MovieCollection}"
<GridView.ItemTemplate>
     <DataTemplate>
        <Grid>
            <Border Background="White">
                   <TexBlock Text="{Binding Title}"/>
            </Border>
             <Grid Background="Black" Margin="0,0,0,0" Opacity="0.75" x:Name="grid_rating"/>
                                <Image Source ="{Binding Path=MovieCollection.Rating.UserRatingURL}" />
             </Grid>
     </DataTemplate>
 </GridView.ItemTemplate>
 </GridView>

问题是我无法使其发挥作用。 UserRatingURL未显示。我甚至把它改成了

<Image Source ="{Binding Path=MovieCollection[0].Rating.UserRatingURL}" />

仍然没有运气。我究竟做错了什么?提前谢谢!

1 个答案:

答案 0 :(得分:0)

尝试删除路径中的MovieCollection。

Image Source =“{Binding Path = Rating.UserRatingURL}”