修复了 https://github.com/irihitech/Ursa.Avalonia/issues/753 当有多个外部 button绑定 不同类型的 NumericUpDown控件的时候,点击button会报错的问题
修正 IPv4Box.cs NumPad.cs NumPad.axaml 文件的编码格式为 utf-8 Semi.Avalonia.Demo.Desktop.Program 增加 SupportedOSPlatform
This commit is contained in:
@@ -1,10 +1,14 @@
|
||||
using System;
|
||||
using Avalonia;
|
||||
using Avalonia;
|
||||
using Avalonia.Dialogs;
|
||||
using Avalonia.Media;
|
||||
using System;
|
||||
using System.Runtime.Versioning;
|
||||
|
||||
namespace Ursa.Demo.Desktop;
|
||||
|
||||
[SupportedOSPlatform("windows")]
|
||||
[SupportedOSPlatform("linux")]
|
||||
[SupportedOSPlatform("macos")]
|
||||
class Program
|
||||
{
|
||||
// Initialization code. Don't use any Avalonia, third-party APIs or any
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<ResourceDictionary
|
||||
<ResourceDictionary
|
||||
xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:u="https://irihi.tech/ursa">
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System.Net;
|
||||
using System.Net;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Metadata;
|
||||
@@ -109,7 +109,7 @@ public class IPv4Box: TemplatedControl
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <EFBFBD>Ƿ<EFBFBD>ʹ<EFBFBD><EFBFBD>С<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
/// 是否使用小键盘输入
|
||||
/// </summary>
|
||||
internal bool IsTargetByNumPad
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Avalonia;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Primitives;
|
||||
using Avalonia.Controls.Templates;
|
||||
@@ -20,7 +20,7 @@ public class NumPad: TemplatedControl
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Target Ŀ<EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD> TextBox <EFBFBD><EFBFBD> TextPresenter <20>ؼ<EFBFBD>
|
||||
/// Target 目标内部的 TextBox 控件
|
||||
/// </summary>
|
||||
private TextBox? _targetInnerText;
|
||||
|
||||
@@ -64,7 +64,7 @@ public class NumPad: TemplatedControl
|
||||
{
|
||||
if(existing.Target is IPv4Box pv4Box)
|
||||
{
|
||||
pv4Box.IsTargetByNumPad = false; // ȡ<EFBFBD><EFBFBD> IPv4Box <EFBFBD><EFBFBD> NumPad <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ
|
||||
pv4Box.IsTargetByNumPad = false; // 取消 IPv4Box 的 NumPad 输入模式
|
||||
}
|
||||
existing.Target = sender as InputElement;
|
||||
existing._targetInnerText = FindTextBoxInTarget((sender as InputElement)!);
|
||||
@@ -107,7 +107,7 @@ public class NumPad: TemplatedControl
|
||||
if (Target is null || o is not NumPadButton b) return;
|
||||
var key = (b.NumMode ? b.NumKey : b.FunctionKey)?? Key.None;
|
||||
|
||||
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD>Ϊ TextBox <20><>Ŀ<EFBFBD><C4BF><EFBFBD>ؼ<EFBFBD><D8BC><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD>ø<EFBFBD> TextBox <20><>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF>
|
||||
// 如果存在内部为 TextBox 的目标控件,则使用该 TextBox 作为输入目标
|
||||
var realTarget = _targetInnerText ?? Target;
|
||||
if (KeyInputMapping.TryGetValue(key, out var s))
|
||||
{
|
||||
@@ -129,28 +129,28 @@ public class NumPad: TemplatedControl
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// <EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD><EFBFBD>ؼ<EFBFBD><EFBFBD>в<EFBFBD><EFBFBD><EFBFBD> TextBox <EFBFBD>ؼ<EFBFBD>
|
||||
/// 在目标控件中查找 TextBox 控件
|
||||
/// </summary>
|
||||
/// <param name="target">Ŀ<EFBFBD><EFBFBD><EFBFBD>ؼ<EFBFBD></param>
|
||||
/// <returns><EFBFBD>ҵ<EFBFBD><EFBFBD><EFBFBD> TextBox<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD><EFBFBD> null</returns>
|
||||
/// <param name="target">目标控件</param>
|
||||
/// <returns>找到的 TextBox,如果没有找到则返回 null</returns>
|
||||
private static TextBox? FindTextBoxInTarget(InputElement target)
|
||||
{
|
||||
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD>걾<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> TextBox
|
||||
// 如果目标本身就是 TextBox
|
||||
if (target is TextBox textBox)
|
||||
return textBox;
|
||||
|
||||
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> TemplatedControl<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD>Ӧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><EFBFBD>
|
||||
// 如果目标是 TemplatedControl,并且已经应用了模板
|
||||
if (target is TemplatedControl templatedControl && templatedControl.IsInitialized)
|
||||
{
|
||||
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><EFBFBD>ģ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> PART_TextBox
|
||||
// 尝试通过模板查找 PART_TextBox
|
||||
if (templatedControl.GetTemplateChildren().FirstOrDefault(c => c is TextBox) is TextBox partTextBox)
|
||||
return partTextBox;
|
||||
}
|
||||
|
||||
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> ILogical<EFBFBD><EFBFBD>ʹ<EFBFBD><EFBFBD> LogicalTree <EFBFBD><EFBFBD>չ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
// 如果目标是 ILogical,使用 LogicalTree 扩展方法查找
|
||||
if (target is ILogical logical)
|
||||
{
|
||||
// ʹ<EFBFBD><EFBFBD> GetLogicalDescendants <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӿؼ<EFBFBD>
|
||||
// 使用 GetLogicalDescendants 方法查找所有逻辑子控件
|
||||
var textBoxes = logical.GetLogicalDescendants().OfType<TextBox>();
|
||||
return textBoxes.FirstOrDefault();
|
||||
}
|
||||
|
||||
@@ -32,6 +32,10 @@ public class NumericIntUpDown : NumericUpDownBase<int>
|
||||
var result = a - b;
|
||||
return result > Value ? Minimum : result;
|
||||
}
|
||||
public override void Clear()
|
||||
{
|
||||
base.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
public class NumericUIntUpDown : NumericUpDownBase<uint>
|
||||
@@ -68,6 +72,10 @@ public class NumericUIntUpDown : NumericUpDownBase<uint>
|
||||
var result = a - b;
|
||||
return result > Value ? Minimum : result;
|
||||
}
|
||||
public override void Clear()
|
||||
{
|
||||
base.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
public class NumericDoubleUpDown : NumericUpDownBase<double>
|
||||
@@ -91,6 +99,10 @@ public class NumericDoubleUpDown : NumericUpDownBase<double>
|
||||
protected override double? Add(double? a, double? b) => a + b;
|
||||
|
||||
protected override double? Minus(double? a, double? b) => a - b;
|
||||
public override void Clear()
|
||||
{
|
||||
base.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
public class NumericByteUpDown : NumericUpDownBase<byte>
|
||||
@@ -122,6 +134,10 @@ public class NumericByteUpDown : NumericUpDownBase<byte>
|
||||
var result = a - b;
|
||||
return (byte?)(result > Value ? Minimum : result);
|
||||
}
|
||||
public override void Clear()
|
||||
{
|
||||
base.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
public class NumericSByteUpDown : NumericUpDownBase<sbyte>
|
||||
@@ -153,6 +169,10 @@ public class NumericSByteUpDown : NumericUpDownBase<sbyte>
|
||||
var result = a - b;
|
||||
return (sbyte?)(result > Value ? Minimum : result);
|
||||
}
|
||||
public override void Clear()
|
||||
{
|
||||
base.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
public class NumericShortUpDown : NumericUpDownBase<short>
|
||||
@@ -184,6 +204,10 @@ public class NumericShortUpDown : NumericUpDownBase<short>
|
||||
var result = a - b;
|
||||
return (short?)(result > Value ? Minimum : result);
|
||||
}
|
||||
public override void Clear()
|
||||
{
|
||||
base.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
public class NumericUShortUpDown : NumericUpDownBase<ushort>
|
||||
@@ -215,6 +239,10 @@ public class NumericUShortUpDown : NumericUpDownBase<ushort>
|
||||
var result = a - b;
|
||||
return (ushort?)(result > Value ? Minimum : result);
|
||||
}
|
||||
public override void Clear()
|
||||
{
|
||||
base.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
public class NumericLongUpDown : NumericUpDownBase<long>
|
||||
@@ -246,6 +274,10 @@ public class NumericLongUpDown : NumericUpDownBase<long>
|
||||
var result = a - b;
|
||||
return result > Value ? Minimum : result;
|
||||
}
|
||||
public override void Clear()
|
||||
{
|
||||
base.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
public class NumericULongUpDown : NumericUpDownBase<ulong>
|
||||
@@ -269,6 +301,10 @@ public class NumericULongUpDown : NumericUpDownBase<ulong>
|
||||
protected override ulong? Add(ulong? a, ulong? b) => a + b;
|
||||
|
||||
protected override ulong? Minus(ulong? a, ulong? b) => a - b;
|
||||
public override void Clear()
|
||||
{
|
||||
base.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
public class NumericFloatUpDown : NumericUpDownBase<float>
|
||||
@@ -292,6 +328,10 @@ public class NumericFloatUpDown : NumericUpDownBase<float>
|
||||
protected override float? Add(float? a, float? b) => a + b;
|
||||
|
||||
protected override float? Minus(float? a, float? b) => a - b;
|
||||
public override void Clear()
|
||||
{
|
||||
base.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
public class NumericDecimalUpDown : NumericUpDownBase<decimal>
|
||||
@@ -315,4 +355,9 @@ public class NumericDecimalUpDown : NumericUpDownBase<decimal>
|
||||
protected override decimal? Add(decimal? a, decimal? b) => a + b;
|
||||
|
||||
protected override decimal? Minus(decimal? a, decimal? b) => a - b;
|
||||
|
||||
public override void Clear()
|
||||
{
|
||||
base.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user