Merge branch 'master' of https://github.com/HandyOrg/HandyControl
This commit is contained in:
commit
b19900953e
6 files changed
+49
-6
No files matched your search
@@ -11,7 +11,9 @@
|
|||||||
<StackPanel Width="300">
|
<StackPanel Width="300">
|
||||||
<hc:Divider/>
|
<hc:Divider/>
|
||||||
<hc:Divider Content="{ex:Lang Key={x:Static langs:LangKeys.Title}}"/>
|
<hc:Divider Content="{ex:Lang Key={x:Static langs:LangKeys.Title}}"/>
|
||||||
<hc:Divider Content="{ex:Lang Key={x:Static langs:LangKeys.Title}}" Padding="10,0"/>
|
<hc:Divider Padding="0">
|
||||||
|
<Button Content="More" hc:IconElement.Geometry="{StaticResource DownGeometry}" hc:IconElement.Height="8"/>
|
||||||
|
</hc:Divider>
|
||||||
<hc:Divider LineStrokeThickness="2" LineStroke="{DynamicResource DarkPrimaryBrush}"/>
|
<hc:Divider LineStrokeThickness="2" LineStroke="{DynamicResource DarkPrimaryBrush}"/>
|
||||||
<hc:Divider LineStrokeDashArray="2,2"/>
|
<hc:Divider LineStrokeDashArray="2,2"/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ public class DropDownElement
|
|||||||
{
|
{
|
||||||
public static readonly DependencyProperty ConsistentWidthProperty = DependencyProperty.RegisterAttached(
|
public static readonly DependencyProperty ConsistentWidthProperty = DependencyProperty.RegisterAttached(
|
||||||
"ConsistentWidth", typeof(bool), typeof(DropDownElement),
|
"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)
|
public static void SetConsistentWidth(DependencyObject element, bool value)
|
||||||
=> element.SetValue(ConsistentWidthProperty, ValueBoxes.BooleanBox(value));
|
=> element.SetValue(ConsistentWidthProperty, ValueBoxes.BooleanBox(value));
|
||||||
|
|||||||
@@ -45,6 +45,12 @@ public class NumericUpDown : Control
|
|||||||
|
|
||||||
public override void OnApplyTemplate()
|
public override void OnApplyTemplate()
|
||||||
{
|
{
|
||||||
|
if (_textBox != null)
|
||||||
|
{
|
||||||
|
_textBox.PreviewKeyDown -= TextBox_PreviewKeyDown;
|
||||||
|
_textBox.TextChanged -= TextBox_TextChanged;
|
||||||
|
}
|
||||||
|
|
||||||
base.OnApplyTemplate();
|
base.OnApplyTemplate();
|
||||||
|
|
||||||
_textBox = GetTemplateChild(ElementTextBox) as TextBox;
|
_textBox = GetTemplateChild(ElementTextBox) as TextBox;
|
||||||
@@ -52,17 +58,42 @@ public class NumericUpDown : Control
|
|||||||
if (_textBox != null)
|
if (_textBox != null)
|
||||||
{
|
{
|
||||||
_textBox.SetBinding(SelectionBrushProperty, new Binding(SelectionBrushProperty.Name) { Source = this });
|
_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 });
|
_textBox.SetBinding(SelectionTextBrushProperty, new Binding(SelectionTextBrushProperty.Name) { Source = this });
|
||||||
#endif
|
#endif
|
||||||
_textBox.SetBinding(SelectionOpacityProperty, new Binding(SelectionOpacityProperty.Name) { Source = this });
|
_textBox.SetBinding(SelectionOpacityProperty, new Binding(SelectionOpacityProperty.Name) { Source = this });
|
||||||
_textBox.SetBinding(CaretBrushProperty, new Binding(CaretBrushProperty.Name) { Source = this });
|
_textBox.SetBinding(CaretBrushProperty, new Binding(CaretBrushProperty.Name) { Source = this });
|
||||||
|
|
||||||
_textBox.PreviewKeyDown += TextBox_PreviewKeyDown;
|
_textBox.PreviewKeyDown += TextBox_PreviewKeyDown;
|
||||||
|
_textBox.TextChanged += TextBox_TextChanged;
|
||||||
|
_textBox.LostFocus += TextBox_LostFocus;
|
||||||
_textBox.Text = CurrentText;
|
_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)
|
private void TextBox_PreviewKeyDown(object sender, KeyEventArgs e)
|
||||||
{
|
{
|
||||||
if (IsReadOnly) return;
|
if (IsReadOnly) return;
|
||||||
@@ -309,7 +340,7 @@ public class NumericUpDown : Control
|
|||||||
set => SetValue(SelectionBrushProperty, value);
|
set => SetValue(SelectionBrushProperty, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !(NET40 || NET45 || NET451 || NET452 || NET46 || NET461 || NET462 || NET47 || NET471 || NET472)
|
#if NET48_OR_GREATER
|
||||||
|
|
||||||
public static readonly DependencyProperty SelectionTextBrushProperty =
|
public static readonly DependencyProperty SelectionTextBrushProperty =
|
||||||
TextBoxBase.SelectionTextBrushProperty.AddOwner(typeof(NumericUpDown));
|
TextBoxBase.SelectionTextBrushProperty.AddOwner(typeof(NumericUpDown));
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
using System.Windows;
|
using System.ComponentModel;
|
||||||
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
|
using System.Windows.Markup;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using HandyControl.Data;
|
using HandyControl.Data;
|
||||||
|
|
||||||
namespace HandyControl.Controls;
|
namespace HandyControl.Controls;
|
||||||
|
|
||||||
|
[ContentProperty(nameof(Content))]
|
||||||
public class Divider : Control
|
public class Divider : Control
|
||||||
{
|
{
|
||||||
public static readonly DependencyProperty ContentProperty = DependencyProperty.Register(
|
public static readonly DependencyProperty ContentProperty = DependencyProperty.Register(
|
||||||
|
|||||||
@@ -20,7 +20,11 @@ public static class WindowHelper
|
|||||||
/// 获取当前应用中处于激活的一个窗口
|
/// 获取当前应用中处于激活的一个窗口
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static Window GetActiveWindow() => Application.Current.Windows.OfType<Window>().SingleOrDefault(x => x.IsActive);
|
public static Window GetActiveWindow()
|
||||||
|
{
|
||||||
|
var activeWindow = InteropMethods.GetActiveWindow();
|
||||||
|
return Application.Current.Windows.OfType<Window>().FirstOrDefault(x => x.GetHandle() == activeWindow);
|
||||||
|
}
|
||||||
|
|
||||||
private static readonly BitArray _cacheValid = new((int) InteropValues.CacheSlot.NumSlots);
|
private static readonly BitArray _cacheValid = new((int) InteropValues.CacheSlot.NumSlots);
|
||||||
|
|
||||||
|
|||||||
@@ -348,6 +348,9 @@ internal class InteropMethods
|
|||||||
[DllImport(InteropValues.ExternDll.User32)]
|
[DllImport(InteropValues.ExternDll.User32)]
|
||||||
internal static extern IntPtr GetWindow(IntPtr hwnd, int nCmd);
|
internal static extern IntPtr GetWindow(IntPtr hwnd, int nCmd);
|
||||||
|
|
||||||
|
[DllImport(InteropValues.ExternDll.User32)]
|
||||||
|
internal static extern IntPtr GetActiveWindow();
|
||||||
|
|
||||||
[DllImport(InteropValues.ExternDll.User32)]
|
[DllImport(InteropValues.ExternDll.User32)]
|
||||||
[return: MarshalAs(UnmanagedType.Bool)]
|
[return: MarshalAs(UnmanagedType.Bool)]
|
||||||
internal static extern bool IsWindowVisible(IntPtr hwnd);
|
internal static extern bool IsWindowVisible(IntPtr hwnd);
|
||||||
|
|||||||
Reference in new issue
Block a user