【发布时间】:2012-08-23 20:45:48
【问题描述】:
我有以下带有 ItemTemplate 的 ListBox
<ListBox SelectionMode="Multiple" ItemsSource="{Binding MyItems}" DisplayMemberPath="Name">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid VerticalAlignment="Stretch" Height="{Binding ActualHeight, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}">
<ContentControl VerticalAlignment="Center" VerticalContentAlignment="Center" Content="{Binding}" />
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
这显示一切都很好,但是 ContentControl 上的命中测试不正确...如果我单击“实际”内容的上方或下方(如果项目的高度比 ContentControl 高,则该项目是'未选中。
如果我将 ControlControl VerticalAlignment 更改为 Stretch,则可以解决问题并且所有点击都会正确突出显示项目...但是我的内容在每个项目中都是顶部对齐的...
我怎样才能正确选择项目?
【问题讨论】: