更新时间:2023-11-28 20:05:22
我们使用以下样式设置一个 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;
}