Hi,
So this is a different behavior. From what I understand, you want to be able to change a value, let's call it "X". When "X" == "AA", you want the column in the grid containing "AA" to have a specific style. When "X" == "BB", you want to clear all the column's style and set a specific style on the column that contains "BB".
In that case, in XAML, don't set any CellContentTemplate for columns. When the value "X" changes, in code-behind, scan the grid to find the DataCell containing the same value as "X". Then set it's parent Column's CellContentTemplate to the specific DataTemplate you want.
The following code snippet will detect "AA" in the grid and set the corresponding column's CellContentTemplate.
So this is a different behavior. From what I understand, you want to be able to change a value, let's call it "X". When "X" == "AA", you want the column in the grid containing "AA" to have a specific style. When "X" == "BB", you want to clear all the column's style and set a specific style on the column that contains "BB".
In that case, in XAML, don't set any CellContentTemplate for columns. When the value "X" changes, in code-behind, scan the grid to find the DataCell containing the same value as "X". Then set it's parent Column's CellContentTemplate to the specific DataTemplate you want.
The following code snippet will detect "AA" in the grid and set the corresponding column's CellContentTemplate.
private void Button_Click( object sender, RoutedEventArgs e )
{
foreach( Column col in ResultGrid.Columns )
{
col.CellContentTemplate = null;
}
foreach( TestCaseResult item in ResultGrid.Items )
{
DataRow row = ResultGrid.GetContainerFromItem( item ) as DataRow;
if( row != null )
{
foreach( DataCell c in row.Cells )
{
if( c != null )
{
if( (c.Content is string) && (string)c.Content == "AA" )
{
DataTemplate template = ResultGrid.Resources[ "test1Template" ] as DataTemplate;
if( template != null )
{
c.ParentColumn.CellContentTemplate = template;
}
}
}
}
}
}
}