Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I make autocomplete and I want go throught with keys up and down in listbox with results. So I need change the focus from textbox to first listbox item.
For change the focus to listbox I used focusmanager. But focusmanager focus the listbox, not the first item. I have to press button down twice to start to walk throught the list. Changing property SelectedClient in listbox doesnt help.

What I have tried:

HTML
<TextBox Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2" Name="Client" Text="{Binding Client}" cal:Message.Attach="[Event KeyUp] = [Action ExecuteFilterView($executionContext)]" Validation.ErrorTemplate="{x:Null}" >
                    <TextBox.Style>
                        <Style>
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding UserCanChooseClient}" Value="True">
                                    <Setter Property="FocusManager.FocusedElement" Value="{Binding ElementName=Clients}"/>
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </TextBox.Style>
                </TextBox>
<ListBox x:Name="Clients" Width="190" Height="auto" MaxHeight="400" Margin="5 28 0 0" cal:Message.Attach="[Event KeyUp] = [Action ExecuteClientsView($executionContext)]; [Event MouseLeftButtonUp]=[Action HandleClientChosenClick($eventArgs)]" ScrollViewer.HorizontalScrollBarVisibility="Hidden" ScrollViewer.VerticalScrollBarVisibility="Hidden" SelectedItem="{Binding Path=SelectedClient}" ItemsSource="{Binding Path=Clients}" DisplayMemberPath="Description" SelectedValuePath="Code"></ListBox>
Posted
Updated 9-Jun-20 23:18pm

1 solution

You don't "focus" ListBox items, you "select" them.

What you probably need to do is handle the keyboard focused event for the ListBox, and inside that handler, set the SelectedIndex to 0.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900