views:

45

answers:

2

I recall in Silverlight the ability to place an Attribute on a given property in the Model for an alternate display name when auto generating columns on a data grid. Is this possible in WPF? I don't want to use the event handler to change the names.

A: 

Check out: How to: Customize Auto-Generated Columns in the DataGrid Control.

Zamboni
That is via handling the event, I don't want to do that and I recall in SL the ability to place an Attribute for a property in the Model to define the alternate text
Aaron
This is how I did it, but that said, please post your solution so I can use it too if/when you find one.
Zamboni
Zamboni, found a solution, check below...
Aaron
A: 

Found it...here is what I was referencing DisplayAttribute, however that does not appear valid in WPF, only SL. For WPF it can be done like this...keeping everything in XAML...

    <dg:DataGrid AutoGenerateColumns="False" ItemsSource="{Binding DatabaseConnections, Mode=Default}">
        <dg:DataGrid.Columns>
            <dg:DataGridTextColumn Header="Display" Binding="{Binding DisplayName}"></dg:DataGridTextColumn>
        </dg:DataGrid.Columns>
    </dg:DataGrid>

...this allows you to change the DisplayName property to get displayed as "Display" in the header of the DataGrid.

Aaron