private void OnPhotoButtonClick(object sender, RoutedEventArgs e) { if (this.DisplayMode == StatusDisplayMode.Base) { System.Windows.Forms.OpenFileDialog fileDialog = new System.Windows.Forms.OpenFileDialog(); fileDialog.Filter = "Image Files (*.jpg;*.jpeg;*.gif;*.png)|*.jpg;*.jpeg;*.gif;*.png"; if (fileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { this.imageFile = DragContainer.ConstrainImage(fileDialog.FileName, FacebookImage.GetDimensionSize(FacebookImageDimensions.Big)); BitmapImage image = new BitmapImage(new Uri(this.imageFile)); image.Freeze(); this.photoImage.Source = image; this.imageFile = fileDialog.FileName; SwitchDisplayMode(StatusDisplayMode.Photo); } } else { this.photoImage.Source = null; SwitchDisplayMode(StatusDisplayMode.Base); } }
private void OnPhotoButtonClick(object sender, RoutedEventArgs e) { if (this.DisplayMode == StatusDisplayMode.Base) { System.Windows.Forms.OpenFileDialog fileDialog = new System.Windows.Forms.OpenFileDialog(); fileDialog.Filter = "Image Files (*.jpg;*.jpeg;*.gif;*.png)|*.jpg;*.jpeg;*.gif;*.png"; if (fileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { this.imageFile = DragContainer.ConstrainImage(fileDialog.FileName, FacebookImage.GetDimensionSize(FacebookImageDimensions.Big)); BitmapImage image = new BitmapImage(new Uri(this.imageFile)); image.Freeze(); this.photoImage.Source = image; this.imageFile = fileDialog.FileName; SwitchDisplayMode(StatusDisplayMode.Photo); // make sure we're still active (if in a popup, the OFD will close us) Action a = () => this.IsActive = true; Dispatcher.BeginInvoke(a, System.Windows.Threading.DispatcherPriority.Background, null); } } else { this.photoImage.Source = null; SwitchDisplayMode(StatusDisplayMode.Base); } }
private void OnUploadExecuted(object sender, ExecutedRoutedEventArgs e) { Assert.IsNull(_workerThread); string albumName = _albumName.Text; string albumDescription = _albumDescription.Text; string albumLocation = _albumLocation.Text; FacebookPhotoAlbum album = _albumsComboBox.SelectedItem as FacebookPhotoAlbum; Page = PhotoUploaderPage.Upload; UploadAlbumName = album != null ? album.Title : albumName; _closeCancelButton.Content = "Cancel"; UploadCount = 0; FileCount = Files.Count; FacebookClientApplication.Current2.MainWindow.SetTaskbarProgress(0); _uploadStatus.Text = ""; // This is terrible, but for some reason I can't get StringFormat to work correctly with the MultiBinding in this case. // This needs to be looked into next time there's any investment made into the PhotoUploadWizard. // (There are other things here that are also terrible (i.e. not localizable, not designable) so this isn't making anything worse...) _uploadPhotoStatusTextBlock.Text = "Uploading photo " + (UploadCount + 1) + " of " + FileCount + " to album " + UploadAlbumName; _workerThread = new Thread(new ThreadStart(() => { try { if (album == null) { album = ServiceProvider.ViewManager.CreatePhotoAlbum(albumName, albumDescription, albumLocation); } int count = 0; foreach (var file in Files) { Dispatcher.BeginInvoke(new Action(() => { BitmapImage image = new BitmapImage(new Uri(file.Path)); image.Freeze(); _nextPhotoImage.Source = image; })); string path = DragContainer.ConstrainImage(file.Path, FacebookImage.GetDimensionSize(FacebookImageDimensions.Big)); ServiceProvider.ViewManager.AddPhotoToAlbum(album, file.Description, path); count++; Dispatcher.BeginInvoke(new Action(() => { UploadCount = count; _uploadPhotoStatusTextBlock.Text = "Uploading photo " + (UploadCount + 1) + " of " + FileCount + " to album " + UploadAlbumName; FacebookClientApplication.Current2.MainWindow.SetTaskbarProgress((float)UploadCount / Files.Count); })); } Dispatcher.BeginInvoke(new Action(() => { ServiceProvider.ViewManager.NavigationCommands.NavigateToContentCommand.Execute(album); FacebookClientApplication.Current2.MainWindow.ClearTaskbarProgress(); Hide(); })); } catch (ThreadAbortException) { } catch (Exception) { Dispatcher.BeginInvoke(new Action(() => { _nextPhotoImage.Source = null; _uploadStatus.Text = "Upload failed."; _closeCancelButton.Content = "Close"; })); } })); _workerThread.Start(); }