如何显示ListViewItem的完整行突出显示?

Pat*_*Pat 4 .net winforms

我有一个ListView,对于View = List,希望列表项填满控件的整个宽度.也就是说,当您单击某个项目时,整个行都会突出显示.

我在ListView或ListViewItem中找不到任何设置来控制这种行为,并且使用空格填充不能很好地工作,因为我不能依赖于固定宽度的文本.

谁知道怎么做?

Tho*_*que 8

您可以将宽度绑定ListViewItem到以下宽度ListView:

...
    <ListView.ItemContainerStyle>
        <Style TargetType="ListViewItem">
            <Setter Property="Width" Value="{Binding ActualWidth, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListView}}}" />
        </Style>
    <ListView.ItemContainerStyle>
...
Run Code Online (Sandbox Code Playgroud)


编辑:您可以将ListView.FullRowSelect属性设置为true

  • 谢谢托马斯.实际上,`FullRowSelect`仅适用于View = Details(http://msdn.microsoft.com/en-us/library/system.windows.forms.listview.fullrowselect.aspx),但我能够切换到详细信息视图没有问题,所以它对我有用. (2认同)