In a WPF application, I create a settings window for customizing keyboard shortcuts.
In text boxes, I handle the KeyDown event and convert the Key event to a human-readable form (as well as the form in which I want to have my data).
The text field is declared as follows
<TextBox Text="{Binding ShortCutText, Mode=TwoWay}"/>
and in the event handler I tried to use both
(sender as TextBox).Text = "...";
and
(sender as TextBox).Clear();
(sender as TextBox).AppendText("...");
In both cases, binding to the viewmodel does not work, the viewmodel still contains old data and is not updated. Linking in the other direction (from the viewmodel to the text box) works fine.
Is there a way to edit TextBox.Text from code without using binding? Or is there an error somewhere else in my process?
source
share