Reputation: 875
Basically, I have a lot of text boxes that will be holding minimum and maximum values for a variable, I would like it so when I hit enter on one text box, it will "commit" the value (without losing focus of the box).
Is this possible?
These are the boxes that I am currently running (copy the format about 10 more times)
<!-- Min -->
<TextBox Name="Min_1" Text=""/>
<TextBox Name="Min_1" Text=""/>
<TextBox Name="Min_2" Text=""/>
<TextBox Name="Min_3" Text=""/>
<TextBox Name="Min_4" Text=""/>
<!-- Value -->
<TextBlock Name="vlu_1"/>
<TextBlock Name="vlu_1"/>
<TextBlock Name="vlu_2"/>
<TextBlock Name="vlu_3"/>
<TextBlock Name="vlu_4"/>
<!-- Max -->
<TextBox Name="txtMax_1" Text=""/>
<TextBox Name="txtMax_1" Text=""/>
<TextBox Name="txtMax_2" Text=""/>
<TextBox Name="txtMax_3" Text=""/>
<TextBox Name="txtMax_4" Text=""/>
Within my C#
code, the vlu_#
is updated every 5 seconds, but this shouldn't affect what I need.
So to break down, I need a way that once I hit the enter
key, the value of vlu_1
etc will change straight away
Upvotes: 0
Views: 1954
Reputation: 371
Should be able to just use the KeyDown event on the textbox to trigger your 'commit' code when enter is pressed.
<TextBox Name="txtMin_1" Text="" Width="20" Margin="193,34,223,134" KeyDown="txtMin_1_KeyDown"/>
and then in code
private void txtMin_1_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
//commit code here
}
}
Upvotes: 1