本文介绍了在列表框中选择文本框项不会更改列表框的选定项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个显示文本框列表的 wpf 列表框.当我单击文本框时,列表框选择不会改变.我必须在 TextBox 旁边单击才能选择列表框项.是否需要为文本框设置一些属性以将点击事件转发到列表框?
I Have a wpf Listbox that display's a list of textboxes. When I click on the Textbox the Listbox selection does not change. I have to click next to the TextBox to select the listbox item. Is there some property I need to set for the Textbox to forward the click event to the Listbox?
推荐答案
我们使用以下样式设置一个 PreviewGotKeyboardFocus,它处理 TextBox 控件和 ComboBoxes 等的所有事件:
We use the following style to set a PreviewGotKeyboardFocus which handles all events of TextBox control and ComboBoxes and such:
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<EventSetter Event="PreviewGotKeyboardFocus" Handler="SelectCurrentItem"/>
</Style>
</ListView.ItemContainerStyle>
然后我们选择后面代码中的行:
And then we select the row in code behind:
protected void SelectCurrentItem(object sender, KeyboardFocusChangedEventArgs e)
{
ListViewItem item = (ListViewItem) sender;
item.IsSelected = true;
}
这篇关于在列表框中选择文本框项不会更改列表框的选定项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!