Unable to enter text in TextBox inside GridView / ListView (WPF)

I have a TextBox and DropDown inside a ListView that is bound to a viewModel. Although comboBox is working fine, I cannot "enter" text inside a TextBox. Backspace / SpaceBar / Ctrl + C / Ctrl + V work fine, but as soon as I press any alphanumeric key, it does not show text in the TextBox.

Also checked using an empty KeyUp / KeyDown / TextChange event handler. It raises the KeyUp / KeyDown event for all types of keystrokes, but TextChange does not fire when any alphanumeric key is pressed.

Please suggest anyone ever come across this problem. Or if there is a way to debug and find the actual problem.

This is my XAML - nothing in the code is behind.

<Window x:Class="Ion.MarketView.Mmi.Plugins.AlertConfigurator.View.AlertConditionItemViewDebug" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" x:Name="aletConditionItems" mc:Ignorable="d" > <Grid > <Grid.Resources> <Style TargetType="ListViewItem"> <Setter Property="HorizontalContentAlignment" Value="Stretch" /> <Setter Property="VerticalContentAlignment" Value="Stretch" /> </Style> </Grid.Resources> <Grid.ColumnDefinitions> <ColumnDefinition Width="*"></ColumnDefinition> <ColumnDefinition Width="75"></ColumnDefinition> </Grid.ColumnDefinitions> <ListView Grid.Column="0" x:Name="lstViewConditionItems" ItemsSource="{Binding ElementName=aletConditionItems, Path=DataContext.Items}" SelectedItem="{Binding ElementName=aletConditionItems, Path=DataContext.SelectedItem, Mode=TwoWay}"> <ListView.View> <GridView> <GridViewColumn Header="Column Id" > <GridViewColumn.CellTemplate> <DataTemplate> <ComboBox SelectedValue="{Binding Path=ColumnId}" Margin="-6,-2,-6,-2" ItemsSource="{Binding ElementName=aletConditionItems, Path=DataContext.ColumnIds}" /> </DataTemplate> </GridViewColumn.CellTemplate> </GridViewColumn> <GridViewColumn Header="Value" Width="100" > <GridViewColumn.CellTemplate> <DataTemplate> <TextBox Text="Only backSpace and SpaceBar works" ></TextBox> </DataTemplate> </GridViewColumn.CellTemplate> </GridViewColumn> </GridView> </ListView.View> </ListView> <StackPanel Orientation="Horizontal" Grid.Column="1" VerticalAlignment="Top" > <Button Content="+" Width="30" Command="{Binding ElementName=aletConditionItems, Path=DataContext.OnAddConditionItem}"></Button> </StackPanel> </Grid> </Window> 

Thank you for your interest.

Note: 1) I am loading this WPF window from a WinForm application.

2) The problem is NOT in binding a textBox with viewModel. I can’t even edit plain text that is hardcoded in the Text property (as in the code above)

3) I have not registered a β€œno” event handler in any parent control.

Solution: According to the links suggested by @HCL, the following code fixed my problem.

 Window window1 = new Window(); ElementHost.EnableModelessKeyboardInterop(window1); //This is needed for Sharing Message Loops Between Win32 and WPF window1.Show(); 
+4
source share
1 answer

I saw this behavior if the wpf window is integrated into the win-forms application. Make a comment if so.

If not, check if you have registered the PreviewKeyDown event handler in the parent element (window, usercontrol, grid), which sets the e.Handled-true property to true (or any other registered event-event handler, with keyboard input).

Since you wrote that copy and paste work, I assume that you did not set TextBox.IsReadOnly in the parent element or in the style or control pattern of the parent element or implicit style.

One more thing: string

 <TextBox Text="Only backSpace and SpaceBar works" ></TextBox> 

Is there really a string that doesn't work, or do you have a binding that doesn't work?

Update:

Good, because this is a win-forms application, you should redirect messages from the win32 message loop. Look here , here and here .

Extra tip: be careful when creating new windows from the embedded WPF window. As far as I remember from the older project, you should also forward messages to any new child window.

+4
source

All Articles