简体   繁体   English

绑定交互触发焦点边框

[英]Binding Interaction Trigger focus border

I have a ListBox where the user can select an item and once he press the right arrow then that item is moved to another panel. 我有一个ListBox,用户可以在其中选择一个项目,一旦按下向右箭头,该项目就会移到另一个面板。

Things works when I use a button to raise the command; 当我使用按钮引发命令时,一切正常。 but when I have the item and press the right arrow then the item is added but the focus in the next one is not properly set, I mean, the border is focused instead another item. 但是,当我有该项目并按向右箭头时,即会添加该项目,但下一个项目的焦点设置不正确,我的意思是,边框已聚焦,而不是另一个项目。

I've already set IsTabStop="False" on the ListBox. 我已经在ListBox上设置了IsTabStop="False"

This is how I'm binding the interaction trigger: 这就是绑定交互触发器的方式:

<i:Interaction.Triggers>
    <i:EventTrigger EventName="KeyDown">
        <cal:ActionMessage MethodName="WasPressed">
            <cal:Parameter Value="$eventArgs"/>
        </cal:ActionMessage>
    </i:EventTrigger>
</i:Interaction.Triggers>

And this is how I'm managing the Trigger to Command raising: 这就是我如何管理引发命令的触发器:

public void WasPressed(KeyEventArgs e)
{
    if (SelectedItem != null && e.Key == Key.Right)
    {
        MoveItem();
    }
}

And this is how it looks after I pressed the right arrow (and the item is added, so it works). 这就是我按下向右箭头后的样子(并添加了该项目,因此可以正常工作)。 Notice the border that appear: 注意出现的边框:

后

Many WPF elements have a trigger on the IsFocused property, that adds a dotted border around it. 许多WPF元素在IsFocused属性上都有一个触发器,该触发器在其周围添加了一个虚线边框。 It seems that this is happening here. 看来这正在发生。

ListBox does not have such a trigger, so you should investigate parent elements. ListBox没有这样的触发器,因此您应该调查父元素。

The easiest way to do this is by editing the existing copy of the template using Blend. 最简单的方法是使用Blend编辑模板的现有副本。

Click on the element, the go on Object -> Edit Style -> Edit a Copy 单击元素,然后转到对象->编辑样式->编辑副本

Then Blend explicitly defines the template and you can look for triggers that define a dotted border. 然后Blend明确定义了模板,您可以查找定义虚线边框的触发器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM