Ciao a tutti,
nella mia applicazione WPF, ho una colonna età che comprendere un range da 0 a 100.
Sto usando un Convert per impostare un colore di sfondo a una singola cella secondo sei range da me impostati....
Vorrei colorare la cella, ma nascondere il valore numerico.
La colorazione funziona, ma non riesco a nascondere il valore...
Come posso fare questo?
Questo è il mio codice:
XAML:
codice:
<DataGridTextColumn Binding="{Binding Age}" Header="Age - Color Range" Width="200">
<!-- COLOR CELLA -->
<DataGridTextColumn.ElementStyle>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="Background" Value="{Binding Age, Converter={StaticResource ColorToCell}}"/>
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
C#
codice:
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;
}
}
Grazie.