Reputation: 2633
I can't seem to find an equivalent of the ListView.FullRowSelect property I loved to use in Windows Forms. Does the WPF ListView support this feature or do I have to migrate it to a DataGrid control? ;)
Any help would be highly appreciated.
Upvotes: 0
Views: 1622
Reputation: 15016
I haven't used WinForms, but if it's like MFC, I'm assuming that you mean that you want the entire row to be highlighted when you click on an item, rather than just the first cell in that row. It is absolutely possible to do in WPF's ListView
control.
Since you didn't post your XAML, I have to assume that you didn't set the View of the ListView
to a GridView
. You do not have to immediately jump to using the DataGrid
control.
Here's an example of a typical way to do it:
<ListView ItemsSource="{Binding Items}">
<ListView.View>
<GridView>
<GridViewColumn DisplayMemberBinding="{Binding Column1}" Header="Column 1" />
<GridViewColumn DisplayMemberBinding="{Binding Column2}" Header="Column 2" />
<GridViewColumn DisplayMemberBinding="{Binding Column3}" Header="Column 3" />
</GridView>
</ListView.View>
</ListView>
Items
could be an ObservableCollection<MyClass>
, where MyClass
has three public string properties called Column1, Column2, and Column3:
public class MyClass
{
public string Column1 { get; set; }
public string Column2 { get; set; }
public string Column3 { get; set; }
}
Highlighting of the entire row is done by default when you use the GridView
.
Upvotes: 2