Reputation: 713
My problem is simple. I have an datagrid and a bound item colection to it. The data shows with out any problem, but i want to format the cells.
The item in collection has simply said this structure:
{
public string Text { get; set; }
public string Title {get;set;}
public Brush BGBrush { get; set; }
public Brush Color { get; set; }
}
i mapped it like this:
<DataGridTextColumn Binding="{Binding Path=Text}" Header="{Binding Path=Title}" Foreground="{Binding Path=Color}" />
Data shows, but the foreground and background doesnt change. Any help will be appreciated. I may be doing it totally wrong, but i am just learning the datagrid. Thanks a lot for help
Upvotes: 0
Views: 172
Reputation: 3318
You need to use DataGridTemplateColumn
for your case as follows :
<DataGridTemplateColumn Header="Column 1" Width="150">
<DataGridTemplateColumn.CellTemplate >
<DataTemplate>
<TextBlock Text="{Binding Text}" Foreground="{Binding Color}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
Hope it helps
Upvotes: 1