Joe M. Doe
Joe M. Doe

Reputation: 61

ListBox CurrentItem / SelectedItem

I'm using a custom ListBoxItem, that's built like this

<Style x:Key="MyListBoxItem"  TargetType="{x:Type ListBoxItem}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type ListBoxItem}">
                <Border>
                    <Border>
                        <ContentPresenter />
                    </Border>
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

It's a basic structure which is modified for the editing control that I need, like this

<Style x:Key="MyListBoxItemText"  TargetType="{x:Type ListBoxItem}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type ListBoxItem}">
                <ListBoxItem Style="{DynamicResource MyListBoxItem}">
                    <TextBox  />
                </ListBoxItem>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

The used ListBoxItem for a certain record of the used ItemsSource of the ListBox is chosen by a StyleSelector.

What I need is a possibility to access the ListBoxItem, thats currently focused. I've tried the following

Can anyone help me, please?

Thanks a lot in advance

Upvotes: 0

Views: 705

Answers (1)

Joe M. Doe
Joe M. Doe

Reputation: 61

Alright, here are my attempts:

<ControlTemplate.Triggers>
    <DataTrigger  Binding="{Binding Selector.IsSelected}" Value="True">
        <Setter Property="Background" Value="Salmon" />
    </DataTrigger>
</ControlTemplate.Triggers>


<ControlTemplate.Triggers>
    <DataTrigger  Binding="{Binding ListBoxItem.IsSelected}" Value="True">
        <Setter Property="Background" Value="Salmon" />
    </DataTrigger>
</ControlTemplate.Triggers>


<ControlTemplate.Triggers>
    <DataTrigger  Binding="{Binding IsSelected}" Value="True">
        <Setter Property="Background" Value="Salmon" />
    </DataTrigger>
</ControlTemplate.Triggers>

In the style of the ListBox the IsSyncronizedWithCurrentItem property is set to true.

Upvotes: 0

Related Questions