2012-04-16 82 views
0

我试图在一个列表框中使用hub tile和两个文本框显示三个不同的值。现在只有三个项目中的两个出现。版本url和版本name和第三项artistName未显示。我正在使用Web客户端来下载JSON数据。这是我目前的设置。 HTTP:// API问题绑定到列表框WP7

首先我的班

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; } 
} 

XAML

   <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); 
} 

JSON字符串代码可以通过插入API进行查看。 beatport.com/catalog/3/beatport/home,变成JSON formatter。谢谢。

UPDATE

第二个列表框势必艺术家

   <ListBox ItemsSource="{Binding Artists}"> 
        <ItemsPanelTemplate> 
         <toolkit:WrapPanel Orientation="Horizontal" /> 
        </ItemsPanelTemplate> 
        <ListBox.ItemTemplate> 
         <DataTemplate> 
          <TextBlock Text="{Binding artistName}" /> 
         </DataTemplate> 
        </ListBox.ItemTemplate>  
       </ListBox> 

回答

-1

我终于能弄明白。我将artists绑定到一个嵌套列表框,并能够获得我想要的布局。这是代码。

    <ListBox x:Name="listRelease" Grid.Row="0" > 
        <ListBox.ItemsPanel> 
         <ItemsPanelTemplate> 
          <toolkit:WrapPanel Orientation="Horizontal" /> 
         </ItemsPanelTemplate> 
        </ListBox.ItemsPanel> 
        <ListBox.ItemTemplate> 
         <DataTemplate> 
          <StackPanel Orientation="Vertical"> 
           <toolkit:HubTile Source="{Binding images.large.url}" Margin="10" IsFrozen="True" /> 
           <TextBlock Text="{Binding name}" Width="173" /> 
           <ListBox ItemsSource="{Binding artists}" ScrollViewer.VerticalScrollBarVisibility="Disabled" > 
            <ListBox.ItemTemplate> 
             <DataTemplate> 
              <StackPanel Orientation="Horizontal" > 
               <TextBlock Text="{Binding name}" Margin="10,0,0,0" Width="173" /> 
              </StackPanel> 
             </DataTemplate> 
            </ListBox.ItemTemplate> 
           </ListBox> 
          </StackPanel> 
         </DataTemplate> 
        </ListBox.ItemTemplate> 
       </ListBox> 
1

没有显示错误输出? 我不认为属性artists.artistName存在,因为它是一个列表?

0

艺术家是一个列表。你必须将它绑定到一个列表控件(例如一个ListBox或ItemsPanel)。

其他可能性:只显示第一艺术家的名单使用的语法如下:

<TextBlock Text="{Binding artists[0].artistName}" Width="173" /> 
+0

抱歉,但是,将它绑定到列表控件是什么意思? – nos9 2012-04-16 19:28:04

+0

看到我的编辑.... – thumbmunkeys 2012-04-16 19:40:04

+0

我可以使用现有的lisbox吗?还是必须创建一个新的?对不起,所有的问题,我还是新来的。 – nos9 2012-04-16 20:01:33

0

结合ItemSourceArtists当你有一个资本化发行。

<ListBox ItemsSource="{Binding Artists}"> 
    <ItemsPanelTemplate> 
     <toolkit:WrapPanel Orientation="Horizontal" /> 
    </ItemsPanelTemplate> 
    <ListBox.ItemTemplate> 
     <DataTemplate> 
      <TextBlock Text="{Binding artistName}" /> 
     </DataTemplate> 
    </ListBox.ItemTemplate>  
</ListBox> 

但是,你FeaturedReleases类定义artists,而不是Artists

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; } 
} 

与你仍然保持,你应该改变结合artists

+0

仍然无法正常工作。你认为我的课程有什么问题吗? – nos9 2012-04-17 02:44:01

+0

@ nos9 - 没有线索。您是否在输出窗口中看到任何绑定错误?清理并上传你的源码树。我会看看它。 – 2012-04-17 02:45:48

+0

这里是源json。 [链接](http://codepad.org/AzGiAE6R) – nos9 2012-04-17 03:10:39