0

I have this ListBox:

<ListBox Name="lbColor"> <ListBoxItem Content="Blue"/> <ListBoxItem Content="Red"/> <ListBoxItem Content="Orange"/> </ListBox> 

This code pre-selects the choice alright, but doesn't set the focus, how can I do that?

public Window1() { InitializeComponent(); lbColor.SelectedIndex = 1; lbColor.Focus = 1; } 

2 Answers 2

3

You can use the Focus method:

public Window1() { InitializeComponent(); lbColor.SelectedIndex = 1; lbColor.Focus(); } 
Sign up to request clarification or add additional context in comments.

Comments

1

I think, that you have to inherit from UIElement-Class and set true to UIElement.IsFocusable. Now you should be able to set the focus to the listbox with lblcolor.Focus()! I hope that this will help.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.