WPF:我不明白 TextCompositionEventArgs 类

发布于 2024-08-04 03:33:13 字数 842 浏览 3 评论 0原文

我不明白 TextCompositionEventArgs 类。

有名为 ControlText、SystemText、Text 的字符串类型成员。然后有一个字段 TextConmosistion,它本身又包含成员 ControlText、SystemText 和 Text,另外还包含字段 SystemCompositionText 和 CompositionText。

public class TextCompositionEventArgs : InputEventArgs
{
  ..
  public string ControlText { get; }
  public string SystemText { get; }
  public string Text { get; }
  public TextComposition TextComposition { get; }
}

public class TextComposition : DispatcherObject
{
  ..
  public string CompositionText { get; protected set; }
  public string ControlText { get; protected set; }
  public string SystemCompositionText { get; protected set; }
  public string SystemText { get; protected set; }
  public string Text { get; protected set; }
}

两个 Text 成员似乎都包含用键盘键入的文本,所有其他字段都包含空字符串。

这些领域有何不同以及它们有什么用处?

I don't understand the class TextCompositionEventArgs.

There are members of type string named ControlText,SystemText,Text. Then there is a field TextConmposistion which itself contains the members ControlText, SystemText and Text again and additionally the fields SystemCompositionText and CompositionText.

public class TextCompositionEventArgs : InputEventArgs
{
  ..
  public string ControlText { get; }
  public string SystemText { get; }
  public string Text { get; }
  public TextComposition TextComposition { get; }
}

public class TextComposition : DispatcherObject
{
  ..
  public string CompositionText { get; protected set; }
  public string ControlText { get; protected set; }
  public string SystemCompositionText { get; protected set; }
  public string SystemText { get; protected set; }
  public string Text { get; protected set; }
}

Both Text members seem to contain the text typed with the keyboard, all other fields contain empty strings.

In which way do these fields differ and what are they good for?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笨死的猪 2024-08-11 03:33:13

TextCompositionEventArgs 处理撰写文本时的更改,因此它有许多处理文本和具体更改内容的属性,以及如何使用它取决于您正在处理的事件。

要理解的基本内容:

  • 文本:这包含导致事件的实际文本 - 通常是用户键入的文本

  • SystemText:这包含系统文本事件,即:如果您按 Alt+字母,您将在此处看到该事件。这通常是不会影响文本框等控件中的文本的击键。

  • ControlText:这是控制文本事件,即:如果您按 Ctrl+字母,您将在此处看到它。与SystemText类似。

通常,如果您只是寻找标准“文本”事件,则只需查看“文本”属性。有关详细信息,请参阅输入概述

TextCompositionEventArgs deals with changes while composing text, so it has many properties dealing with the text and what specifically is changing, and how you use it depends on what events you're handling.

The basic things to understand:

  • Text: This contains that actual text that caused the event - normally the user's typed text

  • SystemText: This contains system text events, ie: if you hit Alt+letter, you'll see the event here. This is normally keystrokes that wouldn't effect text in a control like a text box.

  • ControlText: This is control text events, ie: if you hit Ctrl+letter, you'll see it here. Similar to SystemText.

Normally, if you're just looking for standard "text" events, you'll just want to look at the "Text" property. For details, see the Input Overview.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文