我利用两个不同的网站,将数据引出,以显示我对口的主页。 我愿将这一代码移至用户进入主页之前下载数据。 我不敢确定如何在主页上为我的清单箱提供物品。 在这方面,我迄今为止已经做了些什么。
申请中的法典
private void Application_Launching( object sender, LaunchingEventArgs e)
{
// WebClient jsonGenres
WebClient jsonGenres = new WebClient();
Uri apiGenres = new Uri( "http://api.beatport.com/catalog/3/genres" );
jsonGenres.DownloadStringCompleted += newDownloadStringCompletedEventHandler (jsonGenres_GetDataCompleted);
jsonGenres.DownloadStringAsync(apiGenres);
// WebClient jsonHome
WebClient jsonHome = new WebClient();
Uri apiHome = new Uri ("http://api.beatport.com/catalog/3/beatport/home" );
jsonHome.DownloadStringCompleted += newDownloadStringCompletedEventHandler (jsonHome_GetDataCompleted);
jsonHome.DownloadStringAsync(apiHome);
}
// Deserialize genres data
public void jsonGenres_GetDataCompleted(object sender, DownloadStringCompletedEventArgs e)
{
GenresHome genresData = JsonConvert.DeserializeObject<GenresHome>(e.Result);
ViewModel.Genres = genresData.results;
//this.listGenres.ItemsSource = genresData.results;
}
// Deserialize home page data
public void jsonHome_GetDataCompleted(object sender, DownloadStringCompletedEventArgs e)
{
ReleasesHome homeData = JsonConvert.DeserializeObject<ReleasesHome>(e.Result);
const int limit = 6;
ViewModel.Releases = homeData.results.featuredReleases.Take(limit);
//this.listRelease.ItemsSource = homeData.results.featuredReleases.Take(limit);
}
and my main page xaml code.
<ListBox x:Name="listRelease" ItemsSource="{Binding ReleasesHome}" Grid.Row="0" ScrollViewer.VerticalScrollBarVisibility="Disabled" >
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<toolkit:WrapPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical">
<toolkit:HubTile Source="{Binding images.large.url}" MouseLeftButtonUp="releaseSelectedHandler" Margin="10" IsFrozen="True" />
<TextBlock Text="{Binding name}" Width="173" />
<ListBox ItemsSource="{Binding artists}" Height="28" ScrollViewer.VerticalScrollBarVisibility="Disabled" >
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding name}" Margin="10,0,0,0" Width="173" Style="{StaticResource PhoneTextSubtleStyle}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</controls:PanoramaItem>
<!--Panorama item four-->
<controls:PanoramaItem x:Name="genres" Header="genres">
<!--Single line list-->
<Grid>
<ListBox x:Name="listGenres" ItemsSource="{Binding GenresHome}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical">
<TextBlock x:Name="genresTxtBlock" Text="{Binding name}" MouseLeftButtonUp="genreSelectedHandler" Margin="10,5,0,0" Style="{StaticResource PhoneTextExtraLargeStyle}" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</controls:PanoramaItem>
得到帮助。
<>>>>>
见上文增订的法典和我的看法
public class MainViewModel : INotifyPropertyChanged
{
public MainViewModel()
{
}
private IEnumerable<ResultGenreHome> _genres; // backing field
public IEnumerable<ResultGenreHome> GenresHome
{
get { return _genres; }
set
{
_genres = value;
OnPropertyChanged("GenresHome");
}
}
private IEnumerable<FeaturedReleasesHome> _releases; // backing field
public IEnumerable<FeaturedReleasesHome> ReleasesHome
{
get { return _releases; }
set
{
_releases = value;
OnPropertyChanged("ReleasesHome");
}
}
private void OnPropertyChanged(string p)
{
throw new NotImplementedException();
}
public bool IsDataLoaded
{
get;
private set;
}
public void LoadData()
{
this.IsDataLoaded = true;
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(String propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (null != handler)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
我在主页后面的代码中打下了数据内容。 这是我第一次使用“观点”这样说,不能确切确定我应该在这里做些什么。 该数据没有任何问题,但没有数据显示。