私は 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 に変更すると、問題が解決し、すべてのクリックでアイテムが正しく強調表示されます...しかし、コンテンツは各アイテム内で上揃えになります...
アイテムを正しく選択するにはどうすればよいですか?