我的列表视图不显示绑定到它的数据以寻求帮助我在这里给出了仅显示一个元素的示例我想知道我的代码的问题在哪里请帮助我:(
这是我的代码:
<ListView ItemsSource="{Binding Path=MovieData}">
<ListView.View>
<GridView>
<GridViewColumn DisplayMemberBinding="{Binding Path=MovieId}" Header="Movie Id" />
<GridViewColumn DisplayMemberBinding="{Binding Path=Title}" Header="Title" />
<!-- Can Bind to complex subclass -->
<GridViewColumn Header="Movie(s)">
<GridViewColumn.CellTemplate>
<DataTemplate>
<StackPanel>
<ItemsControl ItemsSource="{Binding Path=MovieImage}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</StackPanel>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<!-- Binding with data triggers -->
<!-- Simple binding -->
<GridViewColumn DisplayMemberBinding="{Binding Path=Recommendation}" Header="Recommendations" />
</GridView>
</ListView.View>
</ListView>
这是我的班级电影:
public class Movie
{
public int MovieId { get; set; }
public string Title { get; set; }
public BitmapImage MovieImage { get; set; }
public string Recommendation { get; set; }
public Movie() { }
public void CreateMovie(int i, string T , string R)
{
MovieId = i;
Title = T;
Recommendation = R;
BitmapImage bi = new BitmapImage();
bi.BeginInit();
bi.UriSource = new Uri(@"http://pierre.chachatelier.fr/programmation/images/mozodojo-original-image.jpg");
bi.EndInit();
MovieImage = bi;
}
}
这里我只添加一个元素进行测试:
public List<Movie> MovieData= new List<Movie>();
Movie m = new Movie();
m.CreateMovie(5, "d", "s");
MovieData.Add(m);