在失去焦点后保持ListViewItem突出显示 [英] Keep ListViewItem highlighted after loosing focus

查看:87
本文介绍了在失去焦点后保持ListViewItem突出显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





想知道如何在将焦点移动到另一个控件后突出显示ListViewItem。



现在我通过在选择项目时设置新的ControlTemplate来改变项目的外观。

对我来说,在WinForms控件中有一个名为ListView.HideSelection的属性。有没有办法在WPF中做到这一点???



无法想象它是那么难,虽然我没有用谷歌搜索到任何地方:((



谢谢

Hi,

wondering how to keep a ListViewItem highlighted after moving focus to another control.

Right now I am changig the appearance of the item by setting a new ControlTemplate when the Item is selected.
Seems to me, there was a property called ListView.HideSelection in the WinForms control. Is there a way to do that in WPF as well???

Can't imagine it is that hard, though I am not getting anywhere with googling :((

Thanks

推荐答案

您好,

我认为您正在为ListViewItem定义新的控件模板。还有一个想法和尝试。现在你正在更改IsSelected触发器右边的模板。你必须在下面的触发器上做出理智的思考





Hi,
I think you are defining new Control template for the ListViewItem.Do one more think and try. Now you are changing the template on the IsSelected trigger right.You have to do the sane think on the following trigger


<MultiTrigger>
                    <MultiTrigger.Conditions>
                        <Condition Property="Selector.IsSelected" Value="True">

                        </Condition>
                        <Condition Property="Selector.IsSelectionActive" Value="False">
                        </Condition>
                    </MultiTrigger.Conditions>
                  -------set the template here too---


我在 MSDN论坛

ListView的灰色画笔资源被覆盖。

I found another soluthen in the MSDN forum.
The gray brush resource of the ListView is overwritten.
<listview>
  <listview.resources>
    <solidcolorbrush x:key="{x:Static SystemColors.ControlBrushKey}" xmlns:x="#unknown">
        Color="{DynamicResource {x:Static SystemColors.HighlightColorKey}}"/>
  </solidcolorbrush></listview.resources>
</listview>


在LostFocus事件中强制突出显示并在GotFocus事件中清除。

将HideSelection设置为True。



Private Sub lvGroup_LostFocus(sender as Object,e As EventArgs)处理lvGroup.LostFocus

lvGroup.SelectedItems(0).BackColor = SystemColors.Highlight

lvGroup.SelectedItems(0).ForeColor = Color.White

End Sub

Private Sub lvGroup_GotFocus(sender as Object,e As EventArgs)处理lvGroup .GotFocus

lvGroup.SelectedItems(0).BackColor = Color.W hite

lvGroup.SelectedItems(0).ForeColor = Color.Black

End Sub
Force highlight in LostFocus Event and clear in GotFocus event.
Set HideSelection to True.

Private Sub lvGroup_LostFocus(sender As Object, e As EventArgs) Handles lvGroup.LostFocus
lvGroup.SelectedItems(0).BackColor = SystemColors.Highlight
lvGroup.SelectedItems(0).ForeColor = Color.White
End Sub
Private Sub lvGroup_GotFocus(sender As Object, e As EventArgs) Handles lvGroup.GotFocus
lvGroup.SelectedItems(0).BackColor = Color.White
lvGroup.SelectedItems(0).ForeColor = Color.Black
End Sub


这篇关于在失去焦点后保持ListViewItem突出显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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