添加/拾取控件时预览的值也按「文本内容」取
之前预览值取的是 UIA Name,富文本/记事本文档会显示成「文本编辑器」「RichEdit Control」 这类标题,让人以为取值键配错了(实际回读是正确的)。现在预览与取值走同一套降级 顺序(Value → Text → Name),全部失败时退回 Name,且不抛异常。 实测(真实 Windows 11 记事本,跨进程只读探测): - 树里有 Document「文本编辑器」,矩形有效,拾取精确命中该节点 - 拾取后保存:Path=/Window[1]/Pane[@ClassName='NotepadTextBox']/Document[@ClassName='RichEditD2DPT'] ValueKey=文本内容,预览值="agfa\r\raaaaa" - 回读同一配置:found=true,value="agfa\r\raaaaa" 回归 27/27 通过
This commit is contained in:
@@ -286,7 +286,9 @@ namespace pacs_win_uia.Services
|
|||||||
if (node.Uia == null) { result.Note = "节点缺少 UIA 数据。"; return result; }
|
if (node.Uia == null) { result.Note = "节点缺少 UIA 数据。"; return result; }
|
||||||
result.ValueKey = ControlValueKeys.TextContent;
|
result.ValueKey = ControlValueKeys.TextContent;
|
||||||
result.RuntimeId = node.Uia.RuntimeId;
|
result.RuntimeId = node.Uia.RuntimeId;
|
||||||
result.Value = node.Uia.Name;
|
// 预览值:和取值键「文本内容」一致(Value → Text → Name),
|
||||||
|
// 否则富文本/输入框会显示成 "RichEdit Control" 这类标题,让人以为取错了。
|
||||||
|
result.Value = ControlValueReader.TryGetTextContent(node.Uia);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
ControlPath.PreparePaths(root);
|
ControlPath.PreparePaths(root);
|
||||||
|
|||||||
@@ -249,6 +249,36 @@ namespace pacs_win_uia.Services
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 供"添加控件/拾取"时预览用:按 Value → Text → Name 取内容,失败返回 null。
|
||||||
|
/// 不抛异常;只在已经需要跨进程调用的路径上使用(新增监控项时)。
|
||||||
|
/// </summary>
|
||||||
|
// 预览用:拿到就返回内容,拿不到返回 null(绝不抛)。
|
||||||
|
public static string TryGetTextContent(UiaElementInfo info)
|
||||||
|
{
|
||||||
|
if (info == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string value;
|
||||||
|
string error;
|
||||||
|
if (TryReadUiaTextContent(info, new ListReadOptions(), out value, out error))
|
||||||
|
{
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
// 预览失败不影响保存:退回 Name。
|
||||||
|
}
|
||||||
|
|
||||||
|
return info.Name;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 读取"这个控件的内容文本"。顺序:ValuePattern → TextPattern → 快照 Name。
|
/// 读取"这个控件的内容文本"。顺序:ValuePattern → TextPattern → 快照 Name。
|
||||||
/// 这样输入框(内容在 Value)、富文本(内容在 Text)和把内容放在 Name 里的客户端都能拿到值。
|
/// 这样输入框(内容在 Value)、富文本(内容在 Text)和把内容放在 Name 里的客户端都能拿到值。
|
||||||
|
|||||||
Reference in New Issue
Block a user