WPF ListViewItem的失去焦点事件 - 如何在活动中得到什么? [英] WPF ListViewItem lost focus event - How to get at the event?

查看:232
本文介绍了WPF ListViewItem的失去焦点事件 - 如何在活动中得到什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有您选择行/项目列表视图。这被链接到在该行显示图像的datatrigger。选择行时只应显示的图像。

I have a listview that you select a row/item on. This is linked to a datatrigger that displays an image on the row. The image should only be displayed when the row is selected.

这部分工作正常,但是当你将焦点移到别的东西,如一个文本框,或显示一个消息框,在一个ListViewItem失去焦点,即该行的亮点是不再显示。问题是,我的形象仍然存在。应该隐藏/折叠当ListView控件失去焦点......这,如果你选择的列表视图不同的项目/行工作正常。

This part works fine, however when you move the focus to something else, such as a textbox, or a messagebox is displayed, the listviewitem loses focus ie the highlight on the row is no longer displayed. The problem is that my image still remains. It should be hidden/collapsed when the listview loses focus... It works fine if you select a different item/row on the listview.

任何人都可以在这方面的帮助吗?

Can anyone help on 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>

问候

TravisPUK

TravisPUK

推荐答案

我想你混淆IsSelected和IsFocused。

I think you're confusing IsSelected and IsFocused.

与结合您的触发器实验 IsFocused 而不是IsSelected让你期望的结果。

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

如果我理解正确的,你只希望图像可见,如果IsSelected和IsFocused都是真实的,否则隐藏。

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

要做到这一点的方法之一是默认可见性设置为可见,然后添加两个触发器设置可见性设为隐藏:一是触发IsSelected =假,另一个触发IsFocused =假

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.

或者相反,设置默认可见性设置为隐藏,并使用与MultiTrigger = IsSelected True和IsFocused = TRUE将其设置为可见可见

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

这篇关于WPF ListViewItem的失去焦点事件 - 如何在活动中得到什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆