tags:

views:

139

answers:

1

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.

+1  A: 

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!

Kieren Johnstone