I have a WPF app where I'm updating output on key press. My code works fine. Only it feels a little bit behind as I'm using KeyUp event. When I try to use KeyDown, it is always a character behind. I have already tried adding UpdateSourceTrigger as shown in the TextBox XAML below
<TextBox
Text="{Binding TheLine, UpdateSourceTrigger=PropertyChanged}"
Behaviors:WatermarkTextBoxBehavior.EnableWatermark="True"
Behaviors:WatermarkTextBoxBehavior.Label="Please enter a numeric value"
Behaviors:WatermarkTextBoxBehavior.LabelStyle="{StaticResource watermarkLabelStyle}"
Grid.Column="0" x:Name="txtLengthFrom" GotFocus="txtLengthFrom_GotFocus" FontSize="15" FontWeight="SemiBold"></TextBox>
All characters are available as expected in the KeyUp event. What can I do to make sure all characters are available in the KeyDown event?
The code behind looks like this
public MainWindow()
{
InitializeComponent();
this.KeyDown += new KeyEventHandler(MainWindow_KeyDown);
}
void MainWindow_KeyDown(object sender, KeyEventArgs e)
{
UpdateOutput();
}
TextBox.TextChanged
. – Jon