WPF ListViewItem lost focus event - How to get at the event?

淺唱寂寞╮ 提交于 2019-12-04 12:09:12

I think you're confusing IsSelected and IsFocused.

Experiment with binding your triggers to IsFocused instead of IsSelected to get your desired result.

If i understand correctly, you only want the image to be visible if both IsSelected and IsFocused are true, otherwise hidden.

One way to do this is to set default Visibility to Visible, and then add two triggers that set Visibility to Hidden: one trigger for IsSelected = False, and another trigger for IsFocused = False.

Or the opposite, set default Visibility to Hidden, and use a MultiTrigger with IsSelected = True and IsFocused = True to set it Visibility to Visible

@Bubblewrap,

Thanks for the information, this pretty well got around the issue. As per below I had to add in both scenarios as the default doesn't seem to take effect... however I haven't tried the MultiTrigger method yet, will do later.

This is what I ended up with in the end.

<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>

Thanks for your help, this will get me past my issue for now. I think that my IsEnabled trigger is probably redundant now though.

Thanks

TravisPUK

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!