WPF:我不明白 TextCompositionEventArgs 类
我不明白 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
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.