private async void Grid_Loaded(object sender, RoutedEventArgs e) { PublicAuthorization publicAuthorization = new PublicAuthorization(); listNewImage = await publicAuthorization.Authorization(); while (listNewImage.Count == 0) { await Task.Delay(10); listNewImage = await publicAuthorization.Authorization(); } double totalWidth = 0; int start = 0; this.ViewModel = new MainPanePhotoViewModel(); while (grvStart.ActualWidth == 0) { await Task.Delay(10); } for (int i = 0; i < ViewModel.NewImages.Count; i++) { var width = ViewModel.NewImages[i].width * 310 / ViewModel.NewImages[i].height; totalWidth += width; if (totalWidth > grvStart.ActualWidth) { for (int j = start; j < i; j++) { ViewModel.NewImages[j].Scale = grvStart.ActualWidth / (totalWidth - width); } start = i; totalWidth = width; } } for (int j = start; j < ViewModel.NewImages.Count; j++) { ViewModel.NewImages[j].Scale = grvStart.ActualWidth / (totalWidth); } grvStart.ItemsSource = ViewModel.NewImages; griNewLoading.Visibility = Visibility.Collapsed; }
private async void btNext_Click(object sender, RoutedEventArgs e) { page++; if (page > 1) { btBack.IsEnabled = true; } RequestParameters.publicAuUri = RequestParameters.defaulUri + "?client_id=" + RequestParameters.client_id + "&page=" + page + "&per_page=30"; listNewImage = await publicAuthorization.Authorization(); await Task.Delay(300); while (listNewImage.Count == 0) { await Task.Delay(10); listNewImage = await publicAuthorization.Authorization(); } double totalWidth = 0; int start = 0; this.ViewModel = new MainPanePhotoViewModel(); while (grvStart.ActualWidth == 0) { await Task.Delay(10); } for (int i = 0; i < ViewModel.NewImages.Count; i++) { var width = ViewModel.NewImages[i].width * 310 / ViewModel.NewImages[i].height; totalWidth += width; if (totalWidth > grvStart.ActualWidth) { for (int j = start; j < i; j++) { ViewModel.NewImages[j].Scale = grvStart.ActualWidth / (totalWidth - width); } start = i; totalWidth = width; } } for (int j = start; j < ViewModel.NewImages.Count; j++) { ViewModel.NewImages[j].Scale = grvStart.ActualWidth / (totalWidth); } grvStart.ItemsSource = ViewModel.NewImages; RequestParameters.publicAuUri = ""; }
private async void Grid_Loaded(object sender, RoutedEventArgs e) { publicAuthorization = new PublicAuthorization(); page = 1; RequestParameters.publicAuUri = RequestParameters.defaulUri + "?client_id=" + RequestParameters.client_id + "&page=" + page + "&per_page=30"; try { listNewImage = await publicAuthorization.Authorization(); } catch (Exception) { NewConnected.Visibility = Visibility.Visible; griNewLoading.Visibility = Visibility.Collapsed; } while (listNewImage.Count == 0) { await Task.Delay(10); try { listNewImage = await publicAuthorization.Authorization(); } catch (Exception) { } } double totalWidth = 0; int start = 0; this.ViewModel = new MainPanePhotoViewModel(); while (grvStart.ActualWidth == 0) { await Task.Delay(10); } for (int i = 0; i < ViewModel.NewImages.Count; i++) { var width = ViewModel.NewImages[i].width * 310 / ViewModel.NewImages[i].height; totalWidth += width; if (totalWidth > grvStart.ActualWidth) { for (int j = start; j < i; j++) { ViewModel.NewImages[j].Scale = grvStart.ActualWidth / (totalWidth - width); } start = i; totalWidth = width; } } for (int j = start; j < ViewModel.NewImages.Count; j++) { ViewModel.NewImages[j].Scale = grvStart.ActualWidth / (totalWidth); } grvStart.ItemsSource = ViewModel.NewImages; RequestParameters.publicAuUri = ""; griNewLoading.Visibility = Visibility.Collapsed; }