1
我試圖將匹配的名稱和圖像綁定到Hub Tile。數據來自輸出JSON的api。我沒有任何反序列化數據的問題,並使用foreach循環將數據添加到我的類。繼承人的設置:WP7發佈綁定文本和圖像到Hub Tile
// 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
是表示集線器瓷磚了。我認爲這是因爲名稱和圖像處於不同的類別,但我一直無法找到解決方案。謝謝您的幫助。
遺憾,但仍然無法正常工作。 – nos9 2012-04-12 18:56:08
沒關係,確實有效。謝謝您的幫助。 – nos9 2012-04-12 19:01:18