开发者

C# datagrid binding

So this is my datagrid:

<DataGrid ItemsSource="{Binding Path=Attributes}" AutoGenerateColumns="True"  Height="95" HorizontalAlignment="Left" Margin="69,99,0,0" Name="dataGrid1" VerticalAlignment="Top" Width="364" Grid.Column="1" />

and the binding to my viewmodel is good.

The itemssource Attributes is an IEnumerable<KeyValuePair<QuestionAttributeDefinition, string>>

the class QuestionAttributeDefinition has a property Name. Now I want to show in my grid:

QuestionAttributeDefinition.Name and the string of the keyvaluepair. But when I want to show this d开发者_高级运维atagrid, as it is implemented now he shows:

Domain.Questions.QuestionAttributeDefinition and the string(the string is ok)

How can I show the property 'Name' of QuestionAttributeDefinition?


Try do define the columns yourself:

<DataGrid ItemsSource="{Binding Path=Attributes}" AutoGenerateColumns="False"  Height="95" HorizontalAlignment="Left" Margin="69,99,0,0" Name="dataGrid1" VerticalAlignment="Top" Width="364" Grid.Column="1">
    <DataGrid.Columns>
        <DataGridTextColumn Header="Name" Binding="{Binding Key.Name}">
        <DataGridTextColumn Header="Value" Binding="{Binding Value}">
    <DataGrid.Columns>
</DataGrid>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜