WPF DataGrid binding to IEnumerable<KeyValuePair<int, CustomType>>
My DataGrid:
<DataGrid ItemsSource="{Binding Path=Question.Variations}" AutoGenerateColumns="False"
Height="97" HorizontalAlignment="Left" Margin="7,6,0,0" Name="dataGrid1"
VerticalAlignment="Top" 开发者_Go百科Width="322">
<DataGrid.Columns>
<DataGridTextColumn Header="Variatienr" Binding="{Binding Key}"/>
<DataGridTextColumn Header="# vraagparameters"
Binding="{Binding Value.QuestionParameters.Count}"/>
<DataGridTextColumn Header="# antwoordparameters"
Binding="{Binding Path=((TypedFieldsVariation)Value).Answers.Count}"/>
</DataGrid.Columns>
</DataGrid>
The following column shows nothing except the header:
<DataGridTextColumn Header="# antwoordparameters"
Binding="{Binding Path=((TypedFieldsVariation)Value).Answers.Count}"/>
I know this is probably wrong, but now my question is how do I show it?
The itemssource
is IEnumerable<KeyValuePair<int, Variation>> Variations
Variation
has 2 subclasses, MultipeChoiceVariation
and TypedFieldsVariation
Now I want the property 'Answers' and I'm sure that all the variations in the itemssource for the datagrid are TypedFieldsVariations
If you lose the brackets and type casting from the Path it should work:
Path=Value.Answers.Count
If it doesn't work how you expect then check your Output window for binding errors, it will give you clues as to what has gone wrong. Just make sure that Count
is a property, not a function.
精彩评论