Hi,
I have a column with a range of age.
I'm using a Convert to set a background color to a single cell of my column 'age'...
I would color the cell but hide the numeric value.
I can set a custom background, but I can't hide the value.
How can I make this?
This is my code:
XAML:
C#
public class ColorToCell : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
int tempValue = int.Parse(value.ToString());
string tempString = "Red";
if (tempValue >= 0 && tempValue <= 20)
tempString = "#FF0000";
if (tempValue > 20 && tempValue <= 40)
tempString = "#F09300";
if (tempValue > 40 && tempValue <= 60)
tempString = "#EDDF00";
if (tempValue > 60 && tempValue <= 80)
tempString = "#CC00FF55";
if (tempValue > 80 && tempValue <= 100)
tempString = "#85AB00";
SolidColorBrush brush = new SolidColorBrush();
BrushConverter conv = new BrushConverter();
brush = conv.ConvertFromString(tempString) as SolidColorBrush;
return brush;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return DependencyProperty.UnsetValue;
}
}
Thanks.

Akhil GargPosted Jan 26, 2015, 4:30 AM
Roberto SalemiPosted Jan 26, 2015, 3:50 AM
i resolved with this two solutions:
I° solution: create a rectangle where bing my value with converter:
II° solution: set color of text as background color of cell:
What do you think?
Akhil GargPosted Jan 24, 2015, 1:15 AM
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate >
<DataTemplate>
<TextBlock Text="Akhil">TextBlock>
DataTemplate>
DataGridTemplateColumn.CellTemplate>
<DataGridTemplateColumn.CellStyle>
<Style TargetType="DataGridCell">
<Setter Property="BorderThickness" Value="2" >Setter>
<Setter Property="BorderBrush" Value="Black" >Setter>
Style>
DataGridTemplateColumn.CellStyle>
DataGridTemplateColumn>
Roberto SalemiPosted Jan 23, 2015, 3:47 AM
Akhil GargPosted Jan 22, 2015, 12:39 PM