Files
PowerToys/src/modules/imageresizer/ui/Views/InputPage.xaml.cs
Jeremy Sinclair eadcf4b120 [Analyzers] Update .editorconfig with rules to relax IDE errors (#36095)
* [Analyzers] Remove duplicate pascal case style from .editorconfig

* [Analyzers] Configured severity for individual IDE and CA rules showing as errors in VS

Set severity for IDE0005, IDE0008, IDE0016, IDE0018, IDE0019, IDE0021, IDE0022, IDE0023, IDE0025, IDE0027, IDE0028, IDE0029, IDE0031, IDE0032, IDE0034, IDE0036, IDE0039, IDE0042, IDE0044, IDE0045, IDE0046, IDE0047, IDE0057, IDE0051, IDE0052, IDE0054, IDE0055, IDE0056, IDE0057, IDE0059, IDE0060, IDE0061, IDE0063, IDE0071, IDE0073, IDE0074, IDE0075, IDE0077, IDE0078, IDE0083, IDE0090, IDE0100, IDE0130, IDE160, IDE180, IDE0200, IDE0240, IDE0250, IDE0251, IDE0260, IDE0270, IDE0290, IDE0300, IDE0301, IDE0305, IDE1005, IDE1006, CA1859, CA2022, CA2263

* [Analyzers] Fix mismatched analyzer descriptions

* [Analyzers] Fix misspelling

* Update .editorconfig

Made the following style rules `silent` instead of `suggestion`: 
- Use explicit type instead of 'var'
- Use expression body for ...
- Use block-scoped namespace

* [Analyzers] Set IDE0290 to silent

* [Analyzers] Remove IDE1006 configuration from .editorconfig in favor of making exclusions for the few entries

* [Analyzers][Indexer] Add IDE1006 suppressions

* [Analyzers][Peek] Add IDE1006 suppression

* [Analyzers][MWB] Add IDE1006 suppression.

* [Analyzers][Plugins] Add IDE1006 suppression

* [Analyzers][ImageResizer] Suppress IDE0073 to retain original copyright

* [Analyzers] Remove IDE0073 severity change in .editorconfig

---------

Co-authored-by: Ani <115020168+drawbyperpetual@users.noreply.github.com>
2024-12-04 12:58:36 -05:00

70 lines
2.7 KiB
C#

#pragma warning disable IDE0073
// 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/
#pragma warning restore IDE0073
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);
}
}
}
}
}