diff --git a/src/View/Window/MainWindow.xaml b/src/View/Window/MainWindow.xaml
index fec35130..f2065d3d 100644
--- a/src/View/Window/MainWindow.xaml
+++ b/src/View/Window/MainWindow.xaml
@@ -13,8 +13,12 @@
Foreground="{DynamicResource SecondaryForeground}"
Icon="/WinMemoryCleaner;component/Resources/Images/win-memory-cleaner.ico"
MouseDown="OnWindowMouseDown"
- ResizeMode="NoResize"
- SizeToContent="WidthAndHeight"
+ Height="700"
+ MinHeight="440"
+ MinWidth="680"
+ ResizeMode="CanResizeWithGrip"
+ SizeToContent="Manual"
+ Width="960"
SnapsToDevicePixels="True"
Title="{x:Static local:Constants+App.Title}"
Topmost="{Binding AlwaysOnTop}"
@@ -27,9 +31,15 @@
BorderThickness="1"
CornerRadius="8"
IsEnabled="{Binding IsBusy, Converter={StaticResource InverseBooleanConverter}, FallbackValue=True}">
-
+
+
+
+
+
+
-
+
@@ -193,23 +203,31 @@
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
-
+
+
+
-
+
@@ -273,10 +289,8 @@
-
@@ -309,19 +323,15 @@
VerticalAlignment="Center"
Visibility="{Binding IsOptimizationKeyValid, Converter={StaticResource InverseBooleanToVisibilityConverter}, FallbackValue={x:Static Visibility.Collapsed}}" />
-
+
+
+
-
-
-
-
-
-
+
@@ -615,17 +625,29 @@
+
-
+
+
-
+
+
+
+
+
+
+
+
+
-
+
\ No newline at end of file
diff --git a/src/View/Window/MainWindow.xaml.cs b/src/View/Window/MainWindow.xaml.cs
index 24f58b93..b4c466e8 100644
--- a/src/View/Window/MainWindow.xaml.cs
+++ b/src/View/Window/MainWindow.xaml.cs
@@ -1,4 +1,5 @@
using System;
+using System.ComponentModel;
using System.Linq;
using System.Threading;
using System.Windows;
@@ -15,6 +16,15 @@ namespace WinMemoryCleaner
///
public partial class MainWindow : View
{
+ private const double ExpandedHeight = 700;
+ private const double ExpandedMinHeight = 440;
+ private const double ExpandedMinWidth = 680;
+ private const double ExpandedWidth = 960;
+
+ private bool? _compactModeApplied;
+ private bool _expandedLayoutApplied;
+ private double _lastExpandedHeight = ExpandedHeight;
+ private double _lastExpandedWidth = ExpandedWidth;
private readonly MainViewModel _viewModel;
///
@@ -28,11 +38,9 @@ public MainWindow()
InitializeComponent();
- // Set initial focus once on load
- Loaded += (s, e) =>
- {
- SetFocusTo(Optimize);
- };
+ // Set initial focus and layout once on load
+ Loaded += OnMainWindowLoaded;
+ Closed += OnMainWindowClosed;
IsVisibleChanged += OnWindowVisibleChanged;
@@ -42,6 +50,7 @@ public MainWindow()
{
_viewModel.OnAddProcessToExclusionListCommandCompleted += OnAddProcessToExclusionListCommandCompleted;
_viewModel.OnLanguageChangeCompleted += Refresh;
+ _viewModel.PropertyChanged += OnViewModelPropertyChanged;
_viewModel.OnNavigateUriCommandCompleted += OnNavigateUriCommandCompleted;
_viewModel.OnOptimizeCommandCompleted += OnOptimizeCommandCompleted;
_viewModel.OnRemoveProcessFromExclusionListCommandCompleted += () => SetFocusTo(ProcessExclusionList);
@@ -69,6 +78,65 @@ public MainWindow()
FontSizeSlider.AddHandler(PreviewMouseLeftButtonDownEvent, sliderPreviewMouseLeftButtonDownEvent, true);
}
+ ///
+ /// Applies the requested compact or expanded window layout.
+ ///
+ /// If set to true, applies compact mode.
+ private void ApplyCompactMode(bool compactMode)
+ {
+ if (_compactModeApplied.HasValue && _compactModeApplied.Value == compactMode)
+ return;
+
+ if (compactMode)
+ {
+ if (_expandedLayoutApplied)
+ {
+ CacheExpandedSize();
+
+ if (WindowState == WindowState.Maximized)
+ WindowState = WindowState.Normal;
+ }
+
+ MinHeight = 0;
+ MinWidth = 0;
+ ResizeMode = ResizeMode.NoResize;
+ SizeToContent = SizeToContent.WidthAndHeight;
+ WindowResizeGrip.Visibility = Visibility.Collapsed;
+ }
+ else
+ {
+ SizeToContent = SizeToContent.Manual;
+ ResizeMode = ResizeMode.CanResizeWithGrip;
+ MinHeight = ExpandedMinHeight;
+ MinWidth = ExpandedMinWidth;
+ Width = _lastExpandedWidth;
+ Height = _lastExpandedHeight;
+ WindowResizeGrip.Visibility = Visibility.Visible;
+ _expandedLayoutApplied = true;
+ }
+
+ _compactModeApplied = compactMode;
+ }
+
+ ///
+ /// Caches a usable expanded window size for the current session.
+ ///
+ private void CacheExpandedSize()
+ {
+ if (WindowState == WindowState.Minimized)
+ return;
+
+ var bounds = WindowState == WindowState.Maximized
+ ? RestoreBounds
+ : new Rect(0, 0, ActualWidth, ActualHeight);
+
+ if (bounds.Width <= 0 || bounds.Height <= 0)
+ return;
+
+ _lastExpandedWidth = bounds.Width;
+ _lastExpandedHeight = bounds.Height;
+ }
+
///
/// Closes the window to the notification area.
///
@@ -186,8 +254,14 @@ private void OnMinimizeButtonClick(object sender, RoutedEventArgs e)
///
protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
{
+ if (e == null)
+ throw new ArgumentNullException("e");
+
base.OnMouseLeftButtonDown(e);
+ if (e.Handled || e.OriginalSource is ResizeGrip || e.Source is ResizeGrip)
+ return;
+
DragMove();
}
@@ -295,6 +369,39 @@ private void OnWindowMouseDown(object sender, MouseButtonEventArgs e)
SetFocusTo(Optimize);
}
+ ///
+ /// Called when the window is closed.
+ ///
+ /// The sender.
+ /// The instance containing the event data.
+ private void OnMainWindowClosed(object sender, EventArgs e)
+ {
+ if (_viewModel != null)
+ _viewModel.PropertyChanged -= OnViewModelPropertyChanged;
+ }
+
+ ///
+ /// Called when the window is loaded.
+ ///
+ /// The sender.
+ /// The instance containing the event data.
+ private void OnMainWindowLoaded(object sender, RoutedEventArgs e)
+ {
+ SetFocusTo(Optimize);
+ ApplyCompactMode(_viewModel != null && _viewModel.CompactMode);
+ }
+
+ ///
+ /// Called when the view model changes.
+ ///
+ /// The sender.
+ /// The instance containing the event data.
+ private void OnViewModelPropertyChanged(object sender, PropertyChangedEventArgs e)
+ {
+ if (e.PropertyName == "CompactMode")
+ ApplyCompactMode(_viewModel.CompactMode);
+ }
+
///
/// Called when the window visibility changes.
///