diff --git a/src/Shared/HandyControlDemo_Shared/UserControl/Controls/DividerDemoCtl.xaml b/src/Shared/HandyControlDemo_Shared/UserControl/Controls/DividerDemoCtl.xaml
index 62c81bf1..13349584 100644
--- a/src/Shared/HandyControlDemo_Shared/UserControl/Controls/DividerDemoCtl.xaml
+++ b/src/Shared/HandyControlDemo_Shared/UserControl/Controls/DividerDemoCtl.xaml
@@ -11,7 +11,9 @@
-
+
+
+
diff --git a/src/Shared/HandyControl_Shared/Controls/Attach/DropDownElement.cs b/src/Shared/HandyControl_Shared/Controls/Attach/DropDownElement.cs
index 20d80110..a32e99b1 100644
--- a/src/Shared/HandyControl_Shared/Controls/Attach/DropDownElement.cs
+++ b/src/Shared/HandyControl_Shared/Controls/Attach/DropDownElement.cs
@@ -7,7 +7,7 @@ public class DropDownElement
{
public static readonly DependencyProperty ConsistentWidthProperty = DependencyProperty.RegisterAttached(
"ConsistentWidth", typeof(bool), typeof(DropDownElement),
- new FrameworkPropertyMetadata(ValueBoxes.TrueBox, FrameworkPropertyMetadataOptions.Inherits));
+ new FrameworkPropertyMetadata(ValueBoxes.FalseBox, FrameworkPropertyMetadataOptions.Inherits));
public static void SetConsistentWidth(DependencyObject element, bool value)
=> element.SetValue(ConsistentWidthProperty, ValueBoxes.BooleanBox(value));
diff --git a/src/Shared/HandyControl_Shared/Controls/Input/NumericUpDown.cs b/src/Shared/HandyControl_Shared/Controls/Input/NumericUpDown.cs
index a8aa262d..9c878bb7 100644
--- a/src/Shared/HandyControl_Shared/Controls/Input/NumericUpDown.cs
+++ b/src/Shared/HandyControl_Shared/Controls/Input/NumericUpDown.cs
@@ -45,6 +45,12 @@ public class NumericUpDown : Control
public override void OnApplyTemplate()
{
+ if (_textBox != null)
+ {
+ _textBox.PreviewKeyDown -= TextBox_PreviewKeyDown;
+ _textBox.TextChanged -= TextBox_TextChanged;
+ }
+
base.OnApplyTemplate();
_textBox = GetTemplateChild(ElementTextBox) as TextBox;
@@ -52,17 +58,42 @@ public class NumericUpDown : Control
if (_textBox != null)
{
_textBox.SetBinding(SelectionBrushProperty, new Binding(SelectionBrushProperty.Name) { Source = this });
-#if !(NET40 || NET45 || NET451 || NET452 || NET46 || NET461 || NET462 || NET47 || NET471 || NET472)
+#if NET48_OR_GREATER
_textBox.SetBinding(SelectionTextBrushProperty, new Binding(SelectionTextBrushProperty.Name) { Source = this });
#endif
_textBox.SetBinding(SelectionOpacityProperty, new Binding(SelectionOpacityProperty.Name) { Source = this });
_textBox.SetBinding(CaretBrushProperty, new Binding(CaretBrushProperty.Name) { Source = this });
_textBox.PreviewKeyDown += TextBox_PreviewKeyDown;
+ _textBox.TextChanged += TextBox_TextChanged;
+ _textBox.LostFocus += TextBox_LostFocus;
_textBox.Text = CurrentText;
}
}
+ private void TextBox_LostFocus(object sender, RoutedEventArgs e)
+ {
+ if (string.IsNullOrWhiteSpace(_textBox.Text))
+ {
+ SetCurrentValue(ValueProperty, ValueBoxes.Double0Box);
+ }
+ else if (double.TryParse(_textBox.Text, out double value))
+ {
+ SetCurrentValue(ValueProperty, value);
+ }
+ }
+
+ private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
+ {
+ if (double.TryParse(_textBox.Text, out double value))
+ {
+ if (value >= Minimum && value <= Maximum)
+ {
+ SetCurrentValue(ValueProperty, value);
+ }
+ }
+ }
+
private void TextBox_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (IsReadOnly) return;
@@ -309,7 +340,7 @@ public class NumericUpDown : Control
set => SetValue(SelectionBrushProperty, value);
}
-#if !(NET40 || NET45 || NET451 || NET452 || NET46 || NET461 || NET462 || NET47 || NET471 || NET472)
+#if NET48_OR_GREATER
public static readonly DependencyProperty SelectionTextBrushProperty =
TextBoxBase.SelectionTextBrushProperty.AddOwner(typeof(NumericUpDown));
diff --git a/src/Shared/HandyControl_Shared/Controls/Other/Divider.cs b/src/Shared/HandyControl_Shared/Controls/Other/Divider.cs
index 94f4cf99..488d10b3 100644
--- a/src/Shared/HandyControl_Shared/Controls/Other/Divider.cs
+++ b/src/Shared/HandyControl_Shared/Controls/Other/Divider.cs
@@ -1,10 +1,13 @@
-using System.Windows;
+using System.ComponentModel;
+using System.Windows;
using System.Windows.Controls;
+using System.Windows.Markup;
using System.Windows.Media;
using HandyControl.Data;
namespace HandyControl.Controls;
+[ContentProperty(nameof(Content))]
public class Divider : Control
{
public static readonly DependencyProperty ContentProperty = DependencyProperty.Register(
diff --git a/src/Shared/HandyControl_Shared/Tools/Helper/WindowHelper.cs b/src/Shared/HandyControl_Shared/Tools/Helper/WindowHelper.cs
index 23ec5e0f..6bab0d0d 100644
--- a/src/Shared/HandyControl_Shared/Tools/Helper/WindowHelper.cs
+++ b/src/Shared/HandyControl_Shared/Tools/Helper/WindowHelper.cs
@@ -20,7 +20,11 @@ public static class WindowHelper
/// 获取当前应用中处于激活的一个窗口
///
///
- public static Window GetActiveWindow() => Application.Current.Windows.OfType().SingleOrDefault(x => x.IsActive);
+ public static Window GetActiveWindow()
+ {
+ var activeWindow = InteropMethods.GetActiveWindow();
+ return Application.Current.Windows.OfType().FirstOrDefault(x => x.GetHandle() == activeWindow);
+ }
private static readonly BitArray _cacheValid = new((int) InteropValues.CacheSlot.NumSlots);
diff --git a/src/Shared/HandyControl_Shared/Tools/Interop/InteropMethods.cs b/src/Shared/HandyControl_Shared/Tools/Interop/InteropMethods.cs
index 4749a44e..23fec702 100644
--- a/src/Shared/HandyControl_Shared/Tools/Interop/InteropMethods.cs
+++ b/src/Shared/HandyControl_Shared/Tools/Interop/InteropMethods.cs
@@ -348,6 +348,9 @@ internal class InteropMethods
[DllImport(InteropValues.ExternDll.User32)]
internal static extern IntPtr GetWindow(IntPtr hwnd, int nCmd);
+ [DllImport(InteropValues.ExternDll.User32)]
+ internal static extern IntPtr GetActiveWindow();
+
[DllImport(InteropValues.ExternDll.User32)]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool IsWindowVisible(IntPtr hwnd);