embedded wpf textbox does not accept input
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 开发者_如何学Gonot 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.
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!
精彩评论