Skip to content

Commit 8ec9966

Browse files
committed
Merge branch 'develop'
2 parents bd3f82a + 91db3b3 commit 8ec9966

File tree

7 files changed

+69
-74
lines changed

7 files changed

+69
-74
lines changed

src/Directory.packages.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
<PackageVersion Include="System.Configuration.ConfigurationManager" Version="8.0.1" />
3030
<PackageVersion Include="System.Memory" Version="4.6.2" />
3131
<PackageVersion Include="System.Runtime.CompilerServices.Unsafe" Version="6.1.1" Condition="'$(TargetFramework)' != 'net8.0-windows'" />
32+
<PackageVersion Include="System.ValueTuple" Version="4.6.1" Condition="$(DefineConstants.Contains(NETCOREAPP)) == false" />
3233

3334
<PackageVersion Include="WpfAnalyzers" Version="4.1.1" />
3435
</ItemGroup>

src/MahApps.Metro/Controls/Dialogs/LoginDialog.cs

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,19 @@ public bool RememberCheckBoxChecked
224224
set => this.SetValue(RememberCheckBoxCheckedProperty, BooleanBoxes.Box(value));
225225
}
226226

227+
/// <summary>Identifies the <see cref="ChangeFocusOnUsernameFieldWithEnterProperty"/> dependency property.</summary>
228+
public static readonly DependencyProperty ChangeFocusOnUsernameFieldWithEnterProperty
229+
= DependencyProperty.Register(nameof(ChangeFocusOnUsernameFieldWithEnter),
230+
typeof(bool),
231+
typeof(LoginDialog),
232+
new PropertyMetadata(default(bool)));
233+
234+
public bool ChangeFocusOnUsernameFieldWithEnter
235+
{
236+
get => (bool) this.GetValue(ChangeFocusOnUsernameFieldWithEnterProperty);
237+
set => this.SetValue(ChangeFocusOnUsernameFieldWithEnterProperty, value);
238+
}
239+
227240
#endregion DependencyProperties
228241

229242
#region Constructor
@@ -257,6 +270,7 @@ internal LoginDialog(MetroWindow? parentWindow, LoginDialogSettings? settings)
257270
this.SetCurrentValue(RememberCheckBoxVisibilityProperty, loginDialogSettings.RememberCheckBoxVisibility);
258271
this.SetCurrentValue(RememberCheckBoxTextProperty, loginDialogSettings.RememberCheckBoxText);
259272
this.SetCurrentValue(RememberCheckBoxCheckedProperty, loginDialogSettings.RememberCheckBoxChecked);
273+
this.SetCurrentValue(ChangeFocusOnUsernameFieldWithEnterProperty, loginDialogSettings.ChangeFocusOnUsernameFieldWithEnter);
260274
}
261275
}
262276

@@ -299,16 +313,23 @@ private void OnKeyDownHandler(object sender, KeyEventArgs e)
299313
}
300314
else if (e.Key == Key.Enter)
301315
{
302-
this.CleanUpHandlers();
303-
304-
this.tcs.TrySetResult(!ReferenceEquals(sender, this.PART_NegativeButton)
305-
? new LoginDialogData
306-
{
307-
Username = this.Username,
308-
SecurePassword = this.PART_PasswordBox?.SecurePassword,
309-
ShouldRemember = this.RememberCheckBoxChecked
310-
}
311-
: null!);
316+
if (PART_TextBox != null && PART_TextBox.IsFocused && ChangeFocusOnUsernameFieldWithEnter)
317+
{
318+
PART_PasswordBox?.Focus();
319+
}
320+
else
321+
{
322+
this.CleanUpHandlers();
323+
324+
this.tcs.TrySetResult(!ReferenceEquals(sender, this.PART_NegativeButton)
325+
? new LoginDialogData
326+
{
327+
Username = this.Username,
328+
SecurePassword = this.PART_PasswordBox?.SecurePassword,
329+
ShouldRemember = this.RememberCheckBoxChecked
330+
}
331+
: null!);
332+
}
312333

313334
e.Handled = true;
314335
}

src/MahApps.Metro/Controls/Dialogs/LoginDialogSettings.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,7 @@ public LoginDialogSettings(MetroDialogSettings? source)
6161
public string RememberCheckBoxText { get; set; } = DefaultRememberCheckBoxText;
6262

6363
public bool RememberCheckBoxChecked { get; set; } = false;
64+
65+
public bool ChangeFocusOnUsernameFieldWithEnter { get; set; }
6466
}
6567
}

src/MahApps.Metro/Controls/MetroWindow.cs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
using System.ComponentModel;
99
using System.Diagnostics.CodeAnalysis;
1010
using System.Linq;
11-
using System.Reflection;
1211
using System.Windows;
1312
using System.Windows.Automation;
1413
using System.Windows.Automation.Peers;
@@ -18,6 +17,7 @@
1817
using System.Windows.Media.Animation;
1918
using System.Windows.Shapes;
2019
using System.Windows.Controls.Primitives;
20+
using System.Windows.Interop;
2121
using Windows.Win32;
2222
using Windows.Win32.Foundation;
2323
using ControlzEx;
@@ -220,7 +220,7 @@ public static readonly DependencyProperty ShowFlyoutsOverDialogsProperty
220220
if (d is MetroWindow window && window.Flyouts != null)
221221
{
222222
// It's not allowed to change this if any Flyout is open
223-
// TODO Find a way to reset the zIndex of any open Flyout if <see cref="ShowFlyoutsOverDialogs"/> is changed by the user
223+
// TODO Find a way to reset the zIndex of any open Flyout if <see cref="ShowFlyoutsOverDialogs"/> is changed by the user
224224
var anyFlyoutOpen = window.Flyouts.GetFlyouts().Any(f => f.IsOpen);
225225
if (anyFlyoutOpen)
226226
{
@@ -1457,16 +1457,6 @@ protected override AutomationPeer OnCreateAutomationPeer()
14571457
return new MetroWindowAutomationPeer(this);
14581458
}
14591459

1460-
protected internal IntPtr CriticalHandle
1461-
{
1462-
get
1463-
{
1464-
this.VerifyAccess();
1465-
var value = typeof(Window).GetProperty("CriticalHandle", BindingFlags.NonPublic | BindingFlags.Instance)?.GetValue(this, new object[0]) ?? IntPtr.Zero;
1466-
return (IntPtr)value;
1467-
}
1468-
}
1469-
14701460
private void ClearWindowEvents()
14711461
{
14721462
if (this.windowTitleThumb != null)
@@ -1642,7 +1632,8 @@ internal static void DoWindowTitleThumbMoveOnDragDelta(IMetroThumb? thumb, Metro
16421632
var wpfPoint = window.PointToScreen(Mouse.GetPosition(window));
16431633
var x = (int)wpfPoint.X;
16441634
var y = (int)wpfPoint.Y;
1645-
PInvoke.SendMessage(new HWND(window.CriticalHandle), PInvoke.WM_NCLBUTTONDOWN, new WPARAM((nuint)HT.CAPTION), new IntPtr(x | (y << 16)));
1635+
var windowHandle = new WindowInteropHelper(window).EnsureHandle();
1636+
PInvoke.SendMessage(new HWND(windowHandle), PInvoke.WM_NCLBUTTONDOWN, new WPARAM((nuint)HT.CAPTION), new IntPtr(x | (y << 16)));
16461637
}
16471638

16481639
internal static void DoWindowTitleThumbChangeWindowStateOnMouseDoubleClick(MetroWindow window, MouseButtonEventArgs mouseButtonEventArgs)

src/MahApps.Metro/Controls/NumericUpDown.cs

Lines changed: 28 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ public static readonly DependencyProperty InterceptArrowKeysProperty
307307
new FrameworkPropertyMetadata(BooleanBoxes.TrueBox));
308308

309309
/// <summary>
310-
/// Gets or sets a value indicating whether the user can use the arrow keys <see cref="Key.Up"/> and <see cref="Key.Down"/> to change the value.
310+
/// Gets or sets a value indicating whether the user can use the arrow keys <see cref="Key.Up"/> and <see cref="Key.Down"/> to change the value.
311311
/// </summary>
312312
[Bindable(true)]
313313
[Category("Behavior")]
@@ -373,7 +373,7 @@ public static readonly DependencyProperty ValueProperty
373373
new FrameworkPropertyMetadata(default(double?),
374374
FrameworkPropertyMetadataOptions.BindsTwoWayByDefault,
375375
OnValuePropertyChanged,
376-
(o, value) => CoerceValue(o, value).Item1));
376+
(o, value) => CoerceValue(o, value).value));
377377

378378
private static void OnValuePropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e)
379379
{
@@ -384,12 +384,12 @@ private static void OnValuePropertyChanged(DependencyObject dependencyObject, De
384384
}
385385

386386
[MustUseReturnValue]
387-
private static Tuple<double?, bool> CoerceValue(DependencyObject d, object? baseValue)
387+
private static (double? value, bool isValid) CoerceValue(DependencyObject d, object? baseValue)
388388
{
389389
var numericUpDown = (NumericUpDown)d;
390390
if (baseValue is null)
391391
{
392-
return new Tuple<double?, bool>(numericUpDown.DefaultValue, false);
392+
return (numericUpDown.DefaultValue, false);
393393
}
394394

395395
var value = ((double?)baseValue).Value;
@@ -401,15 +401,15 @@ private static void OnValuePropertyChanged(DependencyObject dependencyObject, De
401401

402402
if (value < numericUpDown.Minimum)
403403
{
404-
return new Tuple<double?, bool>(numericUpDown.Minimum, true);
404+
return (numericUpDown.Minimum, false);
405405
}
406406

407407
if (value > numericUpDown.Maximum)
408408
{
409-
return new Tuple<double?, bool>(numericUpDown.Maximum, true);
409+
return (numericUpDown.Maximum, false);
410410
}
411411

412-
return new Tuple<double?, bool>(value, false);
412+
return (value, true);
413413
}
414414

415415
/// <summary>
@@ -757,7 +757,7 @@ public static readonly DependencyProperty ButtonUpContentStringFormatProperty
757757
/// <summary>
758758
/// Gets or sets a composite string that specifies how to format the ButtonUpContent property if it is displayed as a string.
759759
/// </summary>
760-
/// <remarks>
760+
/// <remarks>
761761
/// This property is ignored if <seealso cref="ButtonUpContentTemplate"/> is set.
762762
/// </remarks>
763763
[Bindable(true)]
@@ -811,7 +811,7 @@ public static readonly DependencyProperty ButtonDownContentStringFormatProperty
811811
/// <summary>
812812
/// Gets or sets a composite string that specifies how to format the ButtonDownContent property if it is displayed as a string.
813813
/// </summary>
814-
/// <remarks>
814+
/// <remarks>
815815
/// This property is ignored if <seealso cref="ButtonDownContentTemplate"/> is set.
816816
/// </remarks>
817817
[Bindable(true)]
@@ -960,7 +960,7 @@ static NumericUpDown()
960960
EventManager.RegisterClassHandler(typeof(NumericUpDown), GotFocusEvent, new RoutedEventHandler(OnGotFocus));
961961
}
962962

963-
/// <summary>
963+
/// <summary>
964964
/// Called when this element or any below gets focus.
965965
/// </summary>
966966
private static void OnGotFocus(object sender, RoutedEventArgs e)
@@ -1171,7 +1171,8 @@ protected void OnPreviewTextInput(object sender, TextCompositionEventArgs e)
11711171
var fullText = textBox.Text.Remove(textBox.SelectionStart, textBox.SelectionLength).Insert(textBox.CaretIndex, e.Text);
11721172
var textIsValid = this.ValidateText(fullText, out var convertedValue);
11731173
// Value must be valid and not coerced
1174-
e.Handled = !textIsValid || CoerceValue(this, convertedValue as double?).Item2;
1174+
var coerceValue = CoerceValue(this, convertedValue as double?);
1175+
e.Handled = !textIsValid || !coerceValue.isValid;
11751176
this.manualChange = !e.Handled;
11761177
}
11771178

@@ -1195,6 +1196,8 @@ protected virtual void OnValueChanged(double? oldValue, double? newValue)
11951196
this.valueTextBox.Text = null;
11961197
}
11971198

1199+
this.EnableDisableUpDown();
1200+
11981201
if (oldValue != newValue)
11991202
{
12001203
this.RaiseEvent(new RoutedPropertyChangedEventArgs<double?>(oldValue, newValue, ValueChangedEvent));
@@ -1203,22 +1206,12 @@ protected virtual void OnValueChanged(double? oldValue, double? newValue)
12031206
return;
12041207
}
12051208

1206-
if (this.repeatUp != null && !this.repeatUp.IsEnabled)
1207-
{
1208-
this.repeatUp.IsEnabled = true;
1209-
}
1210-
1211-
if (this.repeatDown != null && !this.repeatDown.IsEnabled)
1212-
{
1213-
this.repeatDown.IsEnabled = true;
1214-
}
1209+
this.repeatUp?.SetCurrentValue(RepeatButton.IsEnabledProperty, BooleanBoxes.TrueBox);
1210+
this.repeatDown?.SetCurrentValue(RepeatButton.IsEnabledProperty, BooleanBoxes.TrueBox);
12151211

12161212
if (newValue <= this.Minimum)
12171213
{
1218-
if (this.repeatDown != null)
1219-
{
1220-
this.repeatDown.IsEnabled = false;
1221-
}
1214+
this.repeatDown?.SetCurrentValue(RepeatButton.IsEnabledProperty, BooleanBoxes.FalseBox);
12221215

12231216
this.ResetInternal();
12241217

@@ -1230,12 +1223,10 @@ protected virtual void OnValueChanged(double? oldValue, double? newValue)
12301223

12311224
if (newValue >= this.Maximum)
12321225
{
1233-
if (this.repeatUp != null)
1234-
{
1235-
this.repeatUp.IsEnabled = false;
1236-
}
1226+
this.repeatUp?.SetCurrentValue(RepeatButton.IsEnabledProperty, BooleanBoxes.FalseBox);
12371227

12381228
this.ResetInternal();
1229+
12391230
if (this.IsLoaded)
12401231
{
12411232
this.RaiseEvent(new RoutedEventArgs(MaximumReachedEvent));
@@ -1248,6 +1239,8 @@ protected virtual void OnValueChanged(double? oldValue, double? newValue)
12481239
}
12491240
}
12501241

1242+
this.EnableDisableUpDown();
1243+
12511244
if (oldValue != newValue)
12521245
{
12531246
this.RaiseEvent(new RoutedPropertyChangedEventArgs<double?>(oldValue, newValue, ValueChangedEvent));
@@ -1457,29 +1450,13 @@ private void SetValueTo(double newValue)
14571450
value = this.Minimum;
14581451
}
14591452

1460-
this.SetCurrentValue(ValueProperty, CoerceValue(this, value).Item1);
1461-
}
1462-
1463-
private void EnableDisableDown()
1464-
{
1465-
if (this.repeatDown != null)
1466-
{
1467-
this.repeatDown.IsEnabled = this.Value is null || this.Value > this.Minimum;
1468-
}
1469-
}
1470-
1471-
private void EnableDisableUp()
1472-
{
1473-
if (this.repeatUp != null)
1474-
{
1475-
this.repeatUp.IsEnabled = this.Value is null || this.Value < this.Maximum;
1476-
}
1453+
this.SetCurrentValue(ValueProperty, CoerceValue(this, value).value);
14771454
}
14781455

14791456
private void EnableDisableUpDown()
14801457
{
1481-
this.EnableDisableUp();
1482-
this.EnableDisableDown();
1458+
this.repeatUp?.SetCurrentValue(RepeatButton.IsEnabledProperty, BooleanBoxes.Box(this.Value is null || this.Value < this.Maximum));
1459+
this.repeatDown?.SetCurrentValue(RepeatButton.IsEnabledProperty, BooleanBoxes.Box(this.Value is null || this.Value > this.Minimum));
14831460
}
14841461

14851462
private void OnTextBoxKeyDown(object sender, KeyEventArgs e)
@@ -1578,6 +1555,8 @@ private void ChangeValueFromTextInput(string text)
15781555
return;
15791556
}
15801557

1558+
var oldValue = this.Value;
1559+
15811560
if (string.IsNullOrEmpty(text))
15821561
{
15831562
if (this.DefaultValue.HasValue)
@@ -1603,15 +1582,15 @@ private void ChangeValueFromTextInput(string text)
16031582
else if (this.DefaultValue.HasValue)
16041583
{
16051584
this.SetValueTo(this.DefaultValue.Value);
1606-
this.InternalSetText(this.Value);
1585+
this.InternalSetText(oldValue);
16071586
}
16081587
else
16091588
{
16101589
this.SetCurrentValue(ValueProperty, null);
16111590
}
16121591
}
16131592

1614-
this.OnValueChanged(this.Value, this.Value);
1593+
this.OnValueChanged(oldValue, this.Value);
16151594

16161595
this.manualChange = false;
16171596
}

src/MahApps.Metro/MahApps.Metro.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
<ItemGroup Condition="$(DefineConstants.Contains(NETCOREAPP)) == false">
4545
<Reference Include="System.ComponentModel.DataAnnotations" />
4646
<Reference Include="System.Configuration" />
47+
<PackageReference Include="System.ValueTuple" />
4748
</ItemGroup>
4849

4950
<!-- Items include -->

src/MahApps.Metro/Styles/Themes/Theme.Template.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
xmlns:system="clr-namespace:System;assembly=mscorlib"
88
mc:Ignorable="options">
99

10-
<!-- Matadata -->
10+
<!-- Metadata -->
1111
<system:String x:Key="Theme.Name">{{ThemeName}}</system:String>
1212
<system:String x:Key="Theme.Origin">MahApps.Metro</system:String>
1313
<system:String x:Key="Theme.DisplayName">{{ThemeDisplayName}}</system:String>
@@ -559,4 +559,4 @@
559559
<markup:StaticResource x:Key="MahApps.Brushes.ToggleSwitch.KnobFillOnPressed" ResourceKey="MahApps.Brushes.SystemControlHighlightAltChromeWhite" />
560560
<markup:StaticResource x:Key="MahApps.Brushes.ToggleSwitch.KnobFillOnDisabled" ResourceKey="MahApps.Brushes.SystemControlPageBackgroundBaseLow" />
561561

562-
</ResourceDictionary>
562+
</ResourceDictionary>

0 commit comments

Comments
 (0)