WPF ListViewItem lost focus event - how to get to the event?

I have a list in which you select a row / item. This is due to the data that displays the image in a row. The image should only be displayed when a row is selected.

This part works fine, however, when you move the focus to something else, such as a text field or message, a listviewitem is displayed, that is, the highlight in the line is no longer displayed. The problem is that my image still remains. It should be hidden / compensated when the listview loses focus ... It works great if you select another item / line in the list.

Can anyone help with this please?

<Style x:Key="deleteImageStyle" TargetType="{x:Type Image}">
    <Setter Property="Source" Value="Resources/iconDelete.png" />
    <Setter Property="Margin" Value="0,2,5,0" />
    <Setter Property="Height" Value="16" />
    <Setter Property="Width" Value="16" />
    <Setter Property="HorizontalAlignment" Value="Right" />
    <Setter Property="VerticalAlignment" Value="Top" />
    <Setter Property="Cursor" Value="Hand" />
    <Style.Triggers>
        <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type ListBoxItem}},Path=IsSelected}" Value="True">
            <Setter Property="Visibility" Value="Visible"/>
        </DataTrigger>
        <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type ListBoxItem}},Path=IsSelected}" Value="False">
            <Setter Property="Visibility" Value="Hidden"/>
        </DataTrigger>
        <Trigger Property="IsEnabled" Value="False">
            <Setter Property="Visibility" Value="Hidden" />
        </Trigger>
    </Style.Triggers>
</Style>

Hello

Travispuk

+3
2

, IsSelected IsFocused.

IsFocused IsSelected, .

, , , IsSelected IsFocused , .

- , , Visibility to Hidden: IsSelected = False IsFocused = False.

, MultiTrigger IsSelected = True IsFocused = True,

+3

@Bubblewrap,

, . , ... MultiTrigger, .

.

<Style.Triggers>
            <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type ListBoxItem}},Path=IsSelected}" Value="True">
                <Setter Property="Visibility" Value="Visible"/>
            </DataTrigger>
            <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type ListBoxItem}},Path=IsFocused}" Value="True">
                <Setter Property="Visibility" Value="Visible"/>
            </DataTrigger>
            <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type ListBoxItem}},Path=IsSelected}" Value="False">
                <Setter Property="Visibility" Value="Hidden"/>
            </DataTrigger>
            <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type ListBoxItem}},Path=IsFocused}" Value="False">
                <Setter Property="Visibility" Value="Hidden"/>
            </DataTrigger>
            <Trigger Property="IsEnabled" Value="False">
                <Setter Property="Visibility" Value="Hidden" />
            </Trigger>
        </Style.Triggers>

, . , IsEnabled, , .

TravisPUK

0

All Articles