Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF: I don't understand class TextCompositionEventArgs

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?

like image 507
codymanix Avatar asked Sep 09 '09 20:09

codymanix


1 Answers

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.

like image 51
Reed Copsey Avatar answered Nov 06 '22 08:11

Reed Copsey