From b1054d08b21c6f8126f396825a815876621c41ab Mon Sep 17 00:00:00 2001 From: iTob Date: Fri, 27 Feb 2026 15:57:43 +0100 Subject: [PATCH] open image direct after photo taken --- .../PictureGallery/PictureGalleryPage.xaml.cs | 28 +++++----- src/CamBooth/CamBooth.App/MainWindow.xaml.cs | 52 ++++++++++++++++++- 2 files changed, 65 insertions(+), 15 deletions(-) diff --git a/src/CamBooth/CamBooth.App/Features/PictureGallery/PictureGalleryPage.xaml.cs b/src/CamBooth/CamBooth.App/Features/PictureGallery/PictureGalleryPage.xaml.cs index 501d84b..54ae4f3 100644 --- a/src/CamBooth/CamBooth.App/Features/PictureGallery/PictureGalleryPage.xaml.cs +++ b/src/CamBooth/CamBooth.App/Features/PictureGallery/PictureGalleryPage.xaml.cs @@ -1,4 +1,4 @@ -using System.Windows; +using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Media; @@ -117,16 +117,9 @@ public partial class PictureGalleryPage : Page } - private void Hyperlink_OnClick(object sender, RoutedEventArgs e) + public async Task ShowPhotoDialogAsync(string picturePath) { - Uri? picturePathUri = ((Hyperlink)sender).Tag as Uri; - if (picturePathUri is null) - { - return; - } - - string picturePath = Uri.UnescapeDataString(picturePathUri.AbsolutePath); - Application.Current.Dispatcher.BeginInvoke( + await Application.Current.Dispatcher.InvokeAsync( async () => { this.CloseOpenDialog(); @@ -145,13 +138,10 @@ public partial class PictureGalleryPage : Page contentDialog.CloseButtonAppearance = ControlAppearance.Light; contentDialog.Background = new SolidColorBrush(Colors.White); contentDialog.Foreground = new SolidColorBrush(Colors.White); - // contentDialog.SetCurrentValue(ContentDialog.TitleProperty, "Hello World"); contentDialog.SetCurrentValue(ContentControl.ContentProperty, imageToShow); contentDialog.SetCurrentValue(ContentDialog.CloseButtonTextProperty, "Schließen"); contentDialog.SetCurrentValue(ContentDialog.PrimaryButtonTextProperty, "Drucken"); - // contentDialog.SetCurrentValue(ContentDialog.PrimaryButtonIconProperty, PictureGalleryService.CreateRegularSymbolIcon(SymbolRegular.Print48, Colors.Tomato)); - contentDialog.Tag = picturePath; contentDialog.ButtonClicked += this.ContentDialog_OnButtonClicked; @@ -169,6 +159,18 @@ public partial class PictureGalleryPage : Page } }); } + + private void Hyperlink_OnClick(object sender, RoutedEventArgs e) + { + Uri? picturePathUri = ((Hyperlink)sender).Tag as Uri; + if (picturePathUri is null) + { + return; + } + + string picturePath = Uri.UnescapeDataString(picturePathUri.AbsolutePath); + _ = this.ShowPhotoDialogAsync(picturePath); + } } diff --git a/src/CamBooth/CamBooth.App/MainWindow.xaml.cs b/src/CamBooth/CamBooth.App/MainWindow.xaml.cs index c9ea7bd..cae62e7 100644 --- a/src/CamBooth/CamBooth.App/MainWindow.xaml.cs +++ b/src/CamBooth/CamBooth.App/MainWindow.xaml.cs @@ -1,4 +1,4 @@ -using System.ComponentModel; +using System.ComponentModel; using System.Diagnostics; using System.Threading.Tasks; using System.Windows; @@ -332,10 +332,58 @@ public partial class MainWindow : Window this.GalleryPrompt.Visibility = Visibility.Collapsed; } - private void OpenGalleryFromPrompt(object sender, RoutedEventArgs e) + private async void OpenGalleryFromPrompt(object sender, RoutedEventArgs e) { this.HideGalleryPrompt(); this.SetVisibilityPicturePanel(true); + + // Wait a bit for the page to load before showing the dialog + await Task.Delay(300); + + // Show the latest photo in a dialog + await this.ShowLatestPhotoDialogAsync(); + } + + private async Task ShowLatestPhotoDialogAsync() + { + try + { + // Get the latest photo path + await this._pictureGalleryService.LoadThumbnailsToCache(1); + var latestPhotos = this._pictureGalleryService.ThumbnailsOrderedByNewestDescending; + + if (latestPhotos.Count == 0) + { + this._logger.Error("No photos found in gallery"); + return; + } + + // Get the file path from the BitmapImage source + var latestPhoto = latestPhotos[0]; + if (latestPhoto.UriSource == null) + { + this._logger.Error("Latest photo UriSource is null"); + return; + } + + string photoPath = Uri.UnescapeDataString(latestPhoto.UriSource.AbsolutePath); + this._logger.Info($"Opening photo dialog for: {photoPath}"); + + // Get the current gallery page + if (this.PicturePanel.Content is PictureGalleryPage galleryPage) + { + // Show the photo dialog + await galleryPage.ShowPhotoDialogAsync(photoPath); + } + else + { + this._logger.Error("PicturePanel content is not a PictureGalleryPage"); + } + } + catch (Exception ex) + { + this._logger.Error($"Error showing photo dialog: {ex.Message}"); + } } private void PictureGalleryService_NewPhotoCountChanged(object? sender, int newPhotoCount)