0

I am unable to type in textbox's on a treeview. Some keys do work, such as space and backspace, but no character keys work. The textbox is getting both PreviewKeyDown and KeyDown events (and the up equivalents) for all keys.

Bindings are working correctly and I am getting no errors or exceptions. I tried commenting out the InputBindings, in both the template and the Window itself, but that didn't help. Incidentally, they also appear to not be working and might be a related issue.

The textbox is defined in a HierarchicalDataTemplate, whose visibilities is changed by a DataTrigger based somewhat on the article here.

<HierarchicalDataTemplate x:Key="projectItemTemplate" ItemsSource="{Binding Path=Children}">
     <StackPanel Orientation="Horizontal">
        <TextBlock Name="tb" Text="{Binding Path=Name}"/>
        <TextBox Name="etb" Text="{Binding Path=Name, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" Visibility="Collapsed" PreviewKeyDown="etb_PreviewKeyDown" KeyDown="etb_KeyDown">
           <TextBox.InputBindings>
              <KeyBinding Key="Enter" Command="{Binding Path=RenameCommand}"/>
              <KeyBinding Key="Return" Command="{Binding Path=RenameCommand}"/>
           </TextBox.InputBindings>
        </TextBox>
     </StackPanel>
     <HierarchicalDataTemplate.Triggers>
        <MultiDataTrigger>
           <MultiDataTrigger.Conditions>
              <Condition Binding="{Binding Path=IsEditingName}" Value="True"/>
              <Condition Binding="{Binding Path=IsActive}" Value="True"/>
           </MultiDataTrigger.Conditions>
           <Setter TargetName="tb" Property="Visibility" Value="Collapsed"/>
           <Setter TargetName="etb" Property="Visibility" Value="Visible"/>
        </MultiDataTrigger>
     </HierarchicalDataTemplate.Triggers>
  </HierarchicalDataTemplate>
The Grand User
  • 727
  • 4
  • 14
  • Try removing the event handlers and the `UpdateSourceTrigger` in your binding. Still nothing? – Sphinxxx Oct 02 '13 at 19:56
  • Doesn't help, no. The event handlers were added after the problem was noted and just output a message to the console. Removing the UpdateSourceTrigger doesn't change the controls behavior either, nor would I have expected it to. – The Grand User Oct 02 '13 at 23:04
  • Also cutting things down to just the TextBlcok and TextBox with both being visible doesn't help either. – The Grand User Oct 02 '13 at 23:09
  • If you add another `TextBox` to the `StackPanel`, one without bindings or triggers of any kind, can you type into that one? – Sphinxxx Oct 03 '13 at 07:51
  • No, that doesn't help either. – The Grand User Oct 07 '13 at 18:18
  • I've found I can copy/paste into the text box as normal, just not type regular text. – The Grand User Oct 07 '13 at 22:05
  • Strange.. Are there other controls in your UI that handle key events (thus "stealing" them from the `TextBoxes`)? Maybe the `TreeView` itself, or one of its parent controls? – Sphinxxx Oct 08 '13 at 19:44
  • Nope, nothing else is hooking into the key events except for the ones I added onto the textbox itself to check that it was getting them, which is it. I also added another text box onto the root grid and it's having the same issue. – The Grand User Oct 08 '13 at 20:05
  • Oh, duh, I found the answer. This is a win forms application (That we're slowly changing to WPF) and modeless dialogs need a call to ElementHost.EnableModelessKeyboardInterop. I forgot about that and thought it was a once for all thing, but it's a per window thing. – The Grand User Oct 08 '13 at 20:12
  • Ok, good to know. I've never done much WinForms interop :) – Sphinxxx Oct 08 '13 at 20:16

1 Answers1

0

The answer was simple, I had forgotten to call ElementHost.EnableModelessKeyboardInterop with the WPF window.

The Grand User
  • 727
  • 4
  • 14