1

我正在尝试将匹配的名称和图像绑定到 Hub Tile。数据来自输出 JSON 的 api。我对数据进行反序列化并使用 foreach 循环将数据添加到我的类中没有问题。这是设置:

    // Deserialize home page data
    public void jsonHome_GetDataCompleted(object snder, DownloadStringCompletedEventArgs e)
    {
        NewReleasesCharts homeData = JsonConvert.DeserializeObject<NewReleasesCharts>(e.Result);

        foreach (FeaturedReleases release in homeData.results.featuredReleases)
        {
            int releaseID = release.id;
            string releaseName = release.name;
            string releaseImg = release.images.large.url;

            new ReleaseLarge()
            {
                url = releaseImg
            };
            new FeaturedReleases()
            {
                id = releaseID,
                name = releaseName
            };
        }

        this.listRelease.ItemsSource = homeData.results.featuredReleases;        
    }

这是我的课

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 ReleaseImage images { get; set; }
}

public class ReleaseImage
{
    //public ReleaseSmall small { get; set; }
    public ReleaseMedium medium { get; set; }
    public ReleaseLarge large { 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">
                    <ListBox.ItemsPanel>
                        <ItemsPanelTemplate>
                            <toolkit:WrapPanel Orientation="Horizontal" />
                        </ItemsPanelTemplate>
                    </ListBox.ItemsPanel>
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <toolkit:HubTile Title="{Binding name}" Source="{Binding url}" Margin="10" />
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>

现在只有name显示在 Hub Tile 中。我认为这是因为名称和图像在不同的类中,但我无法找到解决方案。谢谢您的帮助。

4

1 回答 1

1

你有

Source="{Binding img}"

但是在您的模型中,您没有一个名为img.

我会四处走动,但如果有的话,你的绑定应该是这样的:

Source="{Binding images.medium.url}"
于 2012-04-12T18:42:39.640 回答