And*_*lon 15
解决此问题的一种方法是使用行为(或类似行为的附加属性)来订阅RequestBringIntoView事件,ComboBoxItems然后将其设置RequestBringIntoViewEventArgs.Handled为true.这也可以使用EventSetter和代码隐藏小规模完成.
<Style TargetType="ComboBoxItem">
<EventSetter Event="RequestBringIntoView" Handler="OnRequestBringIntoView"/>
</Style>
private void OnRequestBringIntoView(object sender, RequestBringIntoViewEventArgs e)
{
//Allows the keyboard to bring the items into view as expected:
if (Keyboard.IsKeyDown(Key.Down) || Keyboard.IsKeyDown(Key.Up))
return;
e.Handled = true;
}
Run Code Online (Sandbox Code Playgroud)
编辑
我发现你可以通过处理RequestBringIntoView事件ItemsPanel而不是项本身来获得相同的效果.但结果相同:
<ComboBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel RequestBringIntoView="OnRequestBringIntoView"/>
</ItemsPanelTemplate>
</ComboBox.ItemsPanel>
Run Code Online (Sandbox Code Playgroud)
据我所知,这似乎是由灯光底部的物品"部分显示"引起的,其中物品被容器截断.当鼠标移过像这样的部分项目时,WPF将整个项目滚动到视图中,这有时会在底部留下另一个部分项目.
在Winforms中,这可以通过设置来修复.IntegralHeight,但是我可以告诉WPF中不存在这样的属性.如果组合框中的所有项目具有相同的高度,则可以将组合框列表的高度绑定到项目高度的倍数,例如,显示10 x 20px高的项目,将其设置为200.
| 归档时间: |
|
| 查看次数: |
3076 次 |
| 最近记录: |