Click here to Skip to main content
13,056,397 members (125,985 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Need to create a data grid with configurable columns. In that the cell colors will change according to the data bind.

This can be done by data trigger of that column(xaml) - 'only the cell background color'.

But i need to generate the dynamic column from view model class(mvvm wpf). And need to generate data triggers for the corresponding columns.

I have spent lots of day on googling but the end result is null.
Posted 3-Mar-13 23:25pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Hi. try this way :

<DataGridTextColumn Header="Subject" >
                        <Style TargetType="{x:Type TextBox}">
                            <Setter Property="Template">
                                    <ControlTemplate TargetType="{x:Type TextBox}">
                                        <TextBlock Text="{TemplateBinding Text}"/>
                                <DataTrigger Binding="{Binding YourFavoriteProperty}" Value="">
                                    <Setter Property="Background" Value=""/>

if this doesn't work tell me.
Good Luck
vinothezhilan m 4-Mar-13 9:38am
actually i use AutoGenerateColumns="True". how can i add datagridtextcolumn to that datagrid
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Hi.this doesn't work completely. if you complete it, please tell me:

<Style x:Key="myStyle" TargetType="{x:Type DataGridCell}">
           <Setter Property="Template">
                   <ControlTemplate TargetType="{x:Type DataGridCell}">
                       <ContentPresenter >
                                   <TextBox Text="{Binding RelativeSource={RelativeSource AncestorType=DataGridCell, Mode=FindAncestor}, Path=Content}"/>

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170728.5 | Last Updated 4 Mar 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100