我正在尝试将匹配的名称和图像绑定到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中。我认为这是因为名称和图像在不同的类中,但我无法找到解决方案。谢谢你的帮助。
答案 0 :(得分:1)
你有
Source="{Binding img}"
但您的模型中没有任何地方有一个名为img
的公共属性。
我出去了,但如果有的话,你的装订应该是这样的:
Source="{Binding images.medium.url}"