Oleg  Oshkoderov
Oleg Oshkoderov

Reputation: 578

How to make two controls apear as focused?

I'm trying to write a custom control, that have a TextBox and a ListBox inside it's template. But I've found that when I entering a text in the TextBox (so TextBox has focus), ListBox appears as not focused. This makes my control looks like two different controls.

I've read at MSDN that in the WPF there is something called FocusScope but I didn't succeed with it.

So my question is how can I make both ListBox and TextBox controls appear as focused when one of them has keyboard focus within?

Upvotes: 5

Views: 1635

Answers (1)

SvenG
SvenG

Reputation: 5195

Set the IsFocusScope Property to the surrounding Panel (here: StackPanel): The ListBox and the TextBox are treated together in regards of being focussed

  <StackPanel FocusManager.IsFocusScope="True">
    <ListBox >
      <ListBoxItem>Item1</ListBoxItem>
      <ListBoxItem>Item2</ListBoxItem>
    </ListBox>

    <TextBox>Enter Text here...</TextBox>
  </StackPanel>

Upvotes: 0

Related Questions