我尝试使用集线器磁贴和两个文本块在列表框中显示三个不同的值。现在只有三个项目中的两个出现。发布url
和发布 name
和第三项artistName
没有出现。我正在使用网络客户端下载 JSON 数据。这是我目前的设置。
首先我的课
public class NewReleasesCharts
{
//public Metadata metadata { get; set; }
public ResultHome results = new ResultHome();
public IEnumerator<ResultHome> GetEnumerator()
{
return this.results.GetEnumerator();
}
}
public class ResultHome
{
public List<FeaturedReleases> featuredReleases { get; set; }
//public List<FeaturedCharts> featuredCharts { get; set; }
//public List<TopDownloads> topdownloads { get; set; }
//public List<MostPopularReleases> mostPopularReleases { get; set; }
//public List<Components> components { get; set; }
internal IEnumerator<ResultHome> GetEnumerator()
{
throw new NotImplementedException();
}
}
public class FeaturedReleases
{
public int id { get; set; }
public string type { get; set; }
public string name { get; set; }
public string slug { get; set; }
public List<ReleaseArtist> artists { get; set; }
public ReleaseImage images { get; set; }
}
public class ReleaseArtist
{
public int artistID { get; set; }
public string artistName { get; set; }
}
public class ReleaseImage
{
//public ReleaseSmall small { get; set; }
public ReleaseMedium medium { get; set; }
public ReleaseLarge large { get; set; }
}
public class ReleaseMedium
{
public int width { get; set; }
public int height { get; set; }
public string url { get; set; }
public string secureUrl { get; set; }
}
public class ReleaseLarge
{
public int width { get; set; }
public int height { get; set; }
public string url { get; set; }
public string secureUrl { get; set; }
}
xml
<ListBox Grid.Row="0" x:Name="listRelease" ScrollViewer.VerticalScrollBarVisibility="Disabled">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<toolkit:WrapPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<toolkit:HubTile Source="{Binding images.large.url}" Margin="10" />
<TextBlock Text="{Binding name}" Width="173" />
<TextBlock Text="{Binding artists.artistName}" Width="173" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
和背后的代码
public void jsonHome_GetDataCompleted(object snder, DownloadStringCompletedEventArgs e)
{
NewReleasesCharts homeData = JsonConvert.DeserializeObject<NewReleasesCharts>(e.Result);
const int limit = 6;
this.listRelease.ItemsSource = homeData.results.featuredReleases.Take(limit);
}
可以通过将 api:http://api.beatport.com/catalog/3/beatport/home 插入JSON 格式化程序来查看 JSON 字符串。谢谢。
更新
第二个列表框绑定到艺术家
<ListBox ItemsSource="{Binding Artists}">
<ItemsPanelTemplate>
<toolkit:WrapPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding artistName}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>