WPF:我不理解类TextCompositionEventArgs

标签 wpf api events frameworks eventargs

我不理解TextCompositionEventArgs类。

有名为ControlText,SystemText,Text的字符串类型的成员。然后是一个字段TextConmposistion,它本身又包含成员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成员似乎都包含用键盘键入的文本,所有其他字段都包含空字符串。

这些领域在哪些方面有所不同,它们有什么用处?

最佳答案

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

要了解的基本知识:

  • 文本:它包含导致事件的实际文本-通常是用户键入的文本
  • SystemText:它包含系统文本事件,即:如果您按下Alt + letter,则会在此处看到该事件。通常,这是击键操作,不会影响文本框等控件中的文本。
  • ControlText:这是控制文本事件,即:如果您按Ctrl +字母,则会在此处看到它。类似于SystemText。

  • 通常,如果您只是在寻找标准的“文本”事件,则只需要查看“文本”属性即可。有关详细信息,请参见Input Overview

    关于WPF:我不理解类TextCompositionEventArgs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1401794/

    相关文章:

    java - 如何在 JavaFX 中以编程方式触发鼠标事件?

    javascript - 通过点击段落随机背景颜色。我的代码给出了一个错误

    wpf - x :Key ="{x:Type TextBox}" do? 是什么意思

    wpf - 使用 ScatterView 在 MVVM 中拖放

    c# - 在 c# wpf 中,我可以将 listview 列动态构建为类方法吗?

    android - 在 Kotlin 中将 SVG 文件从 API 加载到 Android 中的 ImageView 中

    api - 使用 R 通过 API 访问 google docs 修订历史记录?

    c# - 如何从C#运行.exe

    api - Zune API ZuneCore.dll

    c# - 如果我调用 C# 事件处理程序并调用它,会发生什么情况?