发行结合的ListBox WP7 [英] Issue binding to ListBox WP7

查看:117
本文介绍了发行结合的ListBox WP7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图显示使用HUB瓷砖和两个的TextBlocks一个ListBox中的三个不同的值。现在只有两三个项目出现。发布网址和释放名称和第三项 ARTISTNAME 没有显示出来。我使用的是Web客户端下载JSON数据。下面是我的当前设置。



首先我的班

 公共类NewReleasesCharts 
{
//公开元数据元数据{搞定;组; }
公共ResultHome结果=新ResultHome();
公众的IEnumerator< ResultHome>的GetEnumerator()
{
返回this.results.GetEnumerator();
}
}

公共类ResultHome
{
公开名单< FeaturedReleases> featuredReleases {搞定;组; }

//公开名单< FeaturedCharts> featuredCharts {搞定;组; }
//公开名单< TopDownloads> topdownloads {搞定;组; }
//公开名单< MostPopularReleases> mostPopularReleases {搞定;组; }
//公开名单<成分>组件{搞定;组; }

内部的IEnumerator< ResultHome>的GetEnumerator()
{
抛出新NotImplementedException();
}
}

公共类FeaturedReleases
{
公众诠释ID {搞定;组; }
公共字符串类型{搞定;组; }
公共字符串名称{;组; }
公共字符串蛞蝓{搞定;组; }
公开名单< ReleaseArtist>艺术家{搞定;组; }
公共ReleaseImage图片{搞定;组; }
}

公共类ReleaseArtist
{
公众诠释artistID {搞定;组; }
公共字符串ARTISTNAME {搞定;组; }
}

公共类ReleaseImage
{
//公共ReleaseSmall小{搞定;组; }
公共ReleaseMedium媒体{搞定;组; }
公共ReleaseLarge大{搞定;组; }
}

公共类ReleaseMedium
{
公众诠释宽度{搞定;组; }
公众诠释高度{搞定;组; }
公共字符串URL {搞定;组; }
公共字符串secureUrl {搞定;组; }
}

公共类ReleaseLarge
{
公众诠释宽度{搞定;组; }
公众诠释高度{搞定;组; }
公共字符串URL {搞定;组; }
公共字符串secureUrl {搞定;组; }
}



XAML

 <列表框Grid.Row =0X:NAME =listReleaseScrollViewer.VerticalScrollBarVisibility =已禁用> 
< ListBox.ItemsPanel>
< ItemsPanelTemplate>
<工具箱:WrapPanel方向=横向/>
< / ItemsPanelTemplate>
< /ListBox.ItemsPanel>
< ListBox.ItemTemplate>
<&DataTemplate的GT;
<&StackPanel的GT;
<工具箱:HubTile来源={结合images.large.url}保证金=10/>
< TextBlock的文本={结合NAME}WIDTH =173/>
< TextBlock的文本={结合artists.artistName}WIDTH =173/>
< / StackPanel的>
< / DataTemplate中>
< /ListBox.ItemTemplate>
< /列表框>

和背后

公共无效jsonHome_GetDataCompleted(对象snder,DownloadStringCompletedEventArgs E)
{
NewReleasesCharts homeData = JsonConvert.DeserializeObject< NewReleasesCharts>(e.Result);

const int的极限= 6;

this.listRelease.ItemsSource = homeData.results.featuredReleases.Take(限制); HTTP:
}



JSON字符串可通过插入API看// API .beatport.com /目录/ 3 / beatport /家,到 JSON格式。谢谢你。



更新



二列表框势必艺术家

 < ListBox中的ItemsSource ={结合艺术家}> 
< ItemsPanelTemplate>
<工具箱:WrapPanel方向=横向/>
< / ItemsPanelTemplate>
< ListBox.ItemTemplate>
<&DataTemplate的GT;
< TextBlock的文本={结合ARTISTNAME}/>
< / DataTemplate中>
< /ListBox.ItemTemplate>
< /列表框>


解决方案

我终于能够弄明白。我势必艺术家来嵌套列表框,并能得到我想要的布局。 。下面的代码



 < ListBox的X:名称=listReleaseGrid.Row =0> 
< ListBox.ItemsPanel>
< ItemsPanelTemplate>
<工具箱:WrapPanel方向=横向/>
< / ItemsPanelTemplate>
< /ListBox.ItemsPanel>
< ListBox.ItemTemplate>
<&DataTemplate的GT;
< StackPanel的方向=垂直>
<工具箱:HubTile来源={结合images.large.url}保证金=10的isFrozen =真/>
< TextBlock的文本={结合NAME}WIDTH =173/>
< ListBox中的ItemsSource ={结合艺术家}ScrollViewer.VerticalScrollBarVisibility =已禁用>
< ListBox.ItemTemplate>
<&DataTemplate的GT;
< StackPanel的方向=横向>
< TextBlock的文本={结合NAME}保证金=10,0,0,0WIDTH =173/>
< / StackPanel的>
< / DataTemplate中>
< /ListBox.ItemTemplate>
< /列表框>
< / StackPanel的>
< / DataTemplate中>
< /ListBox.ItemTemplate>
< /列表框>


I'm try to display three different values within a listbox using hub tile and two textblocks. right now only two of the three items appear. The release url and release name and the third item artistName is not showing up. I am using a webclient to download the JSON data. Here is my current setup.

First my Classes

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>

and the code behind

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

The JSON string can be viewed by inserting the api:http://api.beatport.com/catalog/3/beatport/home, into a JSON formatter. Thanks.

UPDATE

Second listbox bound to Artists

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

解决方案

I was finally able to figure it out. I bound artists to a nested listbox and was able to get the layout I wanted. Here's the code.

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

这篇关于发行结合的ListBox WP7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆