Set ListBoxItem.IsSelected when child TextBox is Focused

Posted by jpsstavares on Stack Overflow See other posts from Stack Overflow or by jpsstavares
Published on 2010-06-02T17:41:34Z Indexed on 2010/06/02 17:44 UTC
Read the original article Hit count: 218

Filed under:
|
|
|
|

Hi, I have a typical MVVM scenario: I have a ListBox that is binded to a List of StepsViewModels. I define a DataTemplate so that StepViewModels are rendered as StepViews. The StepView UserControl have a set of labels and TextBoxs.

What I want to do is to select the ListBoxItem that is wrapping the StepView when a textBox is focused. I've tried to create a style for my TextBoxs with the following trigger:

<Trigger Property="IsFocused" Value="true">
    <Setter TargetName="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListBoxItem}}}" Property="IsSelected" Value="True"/>
</Trigger>

But I get an error telling me that TextBoxs don't have an IsSelected property. I now that but the Target is a ListBoxItem. How can I make it work?

© Stack Overflow or respective owner

Related posts about wpf

Related posts about mvvm