Listbox datatemplate - item only selectable by clicking a subelement, not just anywhere on the item

妖精的绣舞 提交于 2019-12-04 04:17:53

As Quartermeister pointed out - you need to set the Background of the Grid - but you also need to set the following style in your resources as ListBoxItems' HorizontalContentAlignment is set to Left by default. (It isn't enough to set it on the ListBox)

<ListBox.Resources>
    <Style TargetType="{x:Type ListBoxItem}">
        <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
    </Style>
</ListBox.Resources>

It sounds like your ListBoxItem is not responding to hit testing. Try setting the Background of the Grid to Transparent:

<Grid Background="Transparent">

The default value is null, which will make the element invisible to hit testing. Setting the background to transparent will not affect the display but will allow the element to be hit. The default style for ListBoxItem will have a Transparent background, but you may have restyled it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!