【发布时间】:2012-11-02 15:44:44
【问题描述】:
我正在尝试创建一个自定义控件,如 https://stackoverflow.com/a/13188979/637142 中所述的控件
到目前为止,我有一个列表视图:
<ListView Name="listBox1">
<!-- Place items horizontaly -->
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" ></StackPanel>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<ListView.ItemContainerStyle>
<Style TargetType="{x:Type ListViewItem}">
<Style.Resources>
<!-- Background for Selected ListViewItem -->
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}"
Color="Yellow"/>
</Style.Resources>
</Style>
</ListView.ItemContainerStyle>
<!-- The items on the listview -->
<ListView.Items>
<TextBlock Margin="5">Test1</TextBlock>
<TextBlock Margin="5">Test2</TextBlock>
<TextBlock Margin="5">Test3</TextBlock>
</ListView.Items>
</ListView>
我现在唯一的问题是当用户使用箭头键选择一个项目时。例如,如果我用鼠标选择一个项目,它的外观是这样的:
但如果我用箭头键选择相同的项目,它的外观是这样的:
如何去除所选项目的黑色虚线边框!
我不想添加 previewKeyDown 事件然后像处理它
if (e.Key == Key.Left)
{
listBox1.SelectedIndex--;
e.Handled = true;
}
else if (e.Key == Key.Right)
{
listBox1.SelectedIndex++;
e.Handled = true;
}
因为我还希望能够使用 shift 键选择多个项目。
【问题讨论】: