2

I put a wpf textbox inside a combobox to allow the user to enter a custom setting. I can read the keypress in the keydown event, but the text in the textbox does not change. What am I missing?

<ComboBoxItem Name="GridSizeCustom">
  <StackPanel Height="30"
              Orientation="Horizontal">
    <TextBlock Text="Grid Size (8 - 200)"
           HorizontalAlignment="Left"
           VerticalAlignment="Top"
           Margin="0"
           />
    <TextBox Name="GridSizeBox"
             KeyDown="test"
             Width="50"
             />
      </StackPanel>
    </ComboBoxItem>

I step through this event handler when I press a key, but no change to the textbox text:

public void test(Object sender, KeyboardEventArgs e) {

int x = 0;

  }

Any help is appreciated. Thanks.

3
  • I tried your code and it works fine. Can you explain you issue a little bit more? Commented May 22, 2010 at 10:54
  • No repro. Post xaml or code that shows the problem. Commented May 22, 2010 at 13:29
  • Hans, that is the code. The text box apparently receives the keystroke because the test function is executed. Be that as it may, the text in the textbox does not change. Commented May 22, 2010 at 21:23

1 Answer 1

2

The standardised way to let the user enter their own text is to have what WPF calls an 'editable' ComboBox:

http://msdn.microsoft.com/en-us/library/system.windows.controls.combobox.iseditable.aspx

<ComboBox IsEditable="True"> ...

Hope that helps, I can feel your pain trying to find a way around the focus/input system!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.