SyntaxEditor hosted in TreeListBox does not handle KeyUp for space key

Grids for WPF Forum

Posted 3 years ago by Cristian
Version: 19.1.0687
Platform: .NET 4.6
Environment: Windows 10 (64-bit)
Avatar

Hello,

We have a scenario where we are using SyntaxEditor controls as items within a TreeListBox. The problem we are facing is that the space key does not work in this configuration - spaces are not added within the text section of the syntax editor.

Pressing the space key works correctly if using a textbox instead of the syntax editor control - Snoop shows us some kind of RoutedUICommand when pressing space.

This can be easily replicated by modifying the provided sample project TreeListBoxChecking - by changing the field template as follows:

<sample:CustomTemplateSelector x:Key="CustomTemplateSelector">
			<sample:CustomTemplateSelector.FieldTemplate>
				<DataTemplate>
					<Grid Margin="-17,0,0,0">
						<Grid.ColumnDefinitions>
							<ColumnDefinition Width="Auto" />
							<ColumnDefinition Width="*" />
							<ColumnDefinition Width="Auto" />
						</Grid.ColumnDefinitions>
						
                        <syntaxeditor:SyntaxEditor IsMultiLine="False" MinWidth="100"/>
                        <TextBox Margin="150,0" MinWidth="100"></TextBox>
						<!--<CheckBox Margin="0,0,4,0" VerticalAlignment="Center"
								  Visibility="{Binding IsCheckable, Converter={StaticResource BooleanToVisibilityConverter}}" 
								  IsChecked="{Binding IsChecked, Mode=TwoWay}" 
								  />
						
						<TextBlock Grid.Column="1" Text="{Binding Name}" TextTrimming="CharacterEllipsis" VerticalAlignment="Center" />
						
						<Button Grid.Column="2" Margin="4,0" Padding="5,0" Content="..." Command="{Binding ShowDialogCommand}"
								Style="{StaticResource {x:Static themes:SharedResourceKeys.ButtonBaseStyleKey}}" />-->
					</Grid>
				</DataTemplate>
			</sample:CustomTemplateSelector.FieldTemplate>

In this configuration, you can clearly see that the space key does not work for the syntax editor but works perfectly for the textbox.

One other thing we've noticed is that the TreeListBoxItem container seems to catch focus when pressing space - but only the very first time.

Please help us in resolving this issue as we need to be able to use the space key within syntax editors hosted in a TreeListBox control.

Kinds regards,

Cristian

Comments (2)

Answer - Posted 3 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Cristian,

The protected virtual TreeListBox.ProcessKeyDown method handles the Space key since that normally is used to toggle selection in a TreeListBoxItem.  That gets called from the TreeListBoxItem.OnKeyDown method override.  You could override the ProcessKeyDown method to prevent the base logic for the Space key.

It seems that OnKeyDown occurs before OnTextInput does, which is what SyntaxEditor uses for a space character.  Since ProcessKeyDown ends up marking the Space key as handled, it never gets to SyntaxEditor's OnTextInput handler.


Actipro Software Support

Posted 3 years ago by Cristian
Avatar

Stellar support as always. Your suggestion works perfectly so thank you very much!

Cristian

The latest build of this product (v24.1.2) was released 1 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.