From 116344ee9b5f3be94b5fc9847f5bc8755f3922e0 Mon Sep 17 00:00:00 2001 From: morkt Date: Sat, 2 Aug 2014 00:42:27 +0400 Subject: [PATCH] implemented fit window to image function. --- ImagePreview.cs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/ImagePreview.cs b/ImagePreview.cs index 74123a4f..e7d6d1f9 100644 --- a/ImagePreview.cs +++ b/ImagePreview.cs @@ -30,8 +30,12 @@ using System.Collections.Generic; using System.Diagnostics; using System.ComponentModel; using System.Windows; +using System.Windows.Controls; +using System.Windows.Input; using System.Windows.Media.Imaging; +using System.Windows.Threading; using GARbro.GUI.Strings; +using GARbro.GUI.Properties; using GameRes; namespace GARbro.GUI @@ -156,6 +160,31 @@ namespace GARbro.GUI }); } + /// + /// Fit window size to image. + /// + private void FitWindowExec (object sender, ExecutedRoutedEventArgs e) + { + var image = PreviewPane.Source; + if (null == image) + return; + var width = image.Width + Settings.Default.lvPanelWidth.Value + 1; + var height = image.Height; + width = Math.Max (ContentGrid.ActualWidth, width); + height = Math.Max (ContentGrid.ActualHeight, height); + if (width > ContentGrid.ActualWidth || height > ContentGrid.ActualHeight) + { + ContentGrid.Width = width; + ContentGrid.Height = height; + this.SizeToContent = SizeToContent.WidthAndHeight; + Dispatcher.InvokeAsync (() => { + this.SizeToContent = SizeToContent.Manual; + ContentGrid.Width = double.NaN; + ContentGrid.Height = double.NaN; + }, DispatcherPriority.ContextIdle); + } + } + void ExtractImage (ArcFile arc, Entry entry, ImageFormat target_format) { using (var file = arc.OpenEntry (entry))