Reputation: 34297
When a user selects an item from a list on my WPF page, I'm trying to show that item's list of enums in another DataGrid:
<DataGrid Grid.Row="1" AutoGenerateColumns="False" IsReadOnly="True"
HeadersVisibility="Column"
ItemsSource="{Binding SelectedAdGroupWithRoles.PrestoRoles}"
SelectedItem="{Binding SelectedPrestoRole}">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding PrestoRole}" Header="Role" Width="*"/>
</DataGrid.Columns>
</DataGrid>
PrestoRole is an enum.
I'm not sure how to set that final binding:
<DataGridTextColumn Binding="{Binding PrestoRole}" Header="Role" Width="*"/>
I've tried a few things, but the PrestoRole name won't display. How can I get it to display?
On a completely separate form, I list every member of the PrestoRole enum in a listbox:
<ListBox Grid.Row="0" ItemsSource="{Binding Roles}" SelectedItem="{Binding SelectedRole}" Height="auto">
The Roles property, on the view model, looks like this:
public List<PrestoRole> Roles
The enum member displays just fine there. I just can't get it to show in the DataGrid.
Upvotes: 1
Views: 241
Reputation: 25201
This should work:
<DataGridTextColumn Binding="{Binding}" Header="Role" Width="*"/>
When you define a column, the column's DataContext
is set to the current item for each row, so all you need to do is bind to it.
Upvotes: 2