esege
esege

Reputation: 45

Giving DataGridTextColumn a static value

In WPF DataGrid, we can bind the DataGridTextColumn value this way.

<DataGridTextColumn Header="MyColumn"
    Binding="{Binding MyColumnValue}" />

What if I wanted to give a static value for this column. Something like

<DataGridTextColumn Header="MyColumn"
    Value="This is a static text" />

I guess it's possible to use a converter, or add an additional property to binded model but I hope there is a simpler way to do this.

Upvotes: 0

Views: 149

Answers (1)

mm8
mm8

Reputation: 169420

Replace the DataGridTextColumn with a DataGridTemplateColumn:

<DataGridTemplateColumn Header="MyColumn">
    <DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <TextBlock Text="This is a static text" />
        </DataTemplate>
    </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>

Or the set the source of the binding to a string:

<DataGridTextColumn Header="MyColumn"
                    Binding="{Binding Source='This is a static text'}" />

Upvotes: 1

Related Questions