Files
PowerToys/src/modules/imageresizer/ui/Views/InputPage.xaml.cs
Jeremy Sinclair 37f2154c86 [Analyzers] Resolve StyleCop issues: SA1516 and SA1616 (#34853)
* [Analyzers][AdvancedPaste] Apply fix for SA1516

* [Analyzers][EnvironmentVariables] Apply fix for SA1516

* [Analyzers][RegistryPreview] Apply fix for SA1516

* [Analyzers][Peek] Apply fix for SA1516

* [Analyzers][PreviewPane] Apply fix for SA1516

* [Analyzers][FancyZones] Apply fix for SA1516

* [Analyzers][PT Run][Plugins] Apply fix for SA1516

* [Analyzers][PT Run] Apply fix for SA1516

* [Analyzers][PT Run][Wox] Apply fix for SA1516

* [Analyzers][Common] Apply fix for SA1516

* [Analyzers][ImageResizer] Apply fix for SA1516

* [Analyzers][ColorPicker] Apply fix for SA1516

* [Analyzers][MouseUtils] Apply fix for SA1516

* [Analyzers][DSC Schema Generator] Apply fix for SA1516

* [Analyzers][FileLocksmith] Apply fix for SA1516

* [Analyzers][Hosts] Apply fix for SA1516

* [Analyzers][MeasureTool] Apply fix for SA1516

* [Analyzers][MouseWithoutBorders] Apply fix for SA1516

* [Analyzers][TextExtractor] Apply fix for SA1516

* [Analyzers][Workspaces] Apply fix for SA1516

* [Analyzers][Awake] Apply fix for SA1516

* [Analyzers][PowerAccent] Apply fix for SA1516

* [Analyzers][RegistryPreview] Apply fix for SA1516

* [Analyzers][Settings] Apply fix for SA1516

* [Analyzers][MouseWithoutBorders] Apply fix for SA1616
2024-09-16 21:09:43 +01:00

68 lines
2.7 KiB
C#

// Copyright (c) Brice Lambson
// The Brice Lambson licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
// Code forked from Brice Lambson's https://github.com/bricelam/ImageResizer/
using System.Windows.Controls;
using System.Windows.Input;
using ImageResizer.ViewModels;
using Wpf.Ui.Controls;
using static ImageResizer.ViewModels.InputViewModel;
namespace ImageResizer.Views
{
public partial class InputPage : UserControl
{
public InputPage()
=> InitializeComponent();
/// <summary>
/// Pressing Enter key doesn't update value. PropertyChanged is only updated after losing focus to NumberBox.
/// We add this workaround the UI limitations and might need to be revisited or not needed anymore if we upgrade to WinUI3.
/// This function handles the KeyDown event for a NumberBox control.
/// It checks if the key pressed is 'Enter'.
/// According to the NumberBox name, it creates an instance of the KeyPressParams class with the appropriate dimension (Width or Height) and the parsed double value.
/// </summary>
private void Button_KeyDown(object sender, KeyEventArgs e)
{
// Check if the key pressed is the 'Enter' key
if (e.Key == Key.Enter)
{
var numberBox = sender as NumberBox;
var viewModel = (InputViewModel)DataContext;
KeyPressParams keyParams;
if (double.TryParse(((System.Windows.Controls.TextBox)e.OriginalSource).Text, out double number))
{
// Determine which NumberBox triggered the event based on its name
switch (numberBox.Name)
{
case "WidthNumberBox":
keyParams = new KeyPressParams
{
Value = number,
Dimension = Dimension.Width,
};
break;
case "HeightNumberBox":
keyParams = new KeyPressParams
{
Value = number,
Dimension = Dimension.Height,
};
break;
default:
// Return without EnterKeyPressedCommand executed
return;
}
viewModel.EnterKeyPressedCommand.Execute(keyParams);
}
}
}
}
}