TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Roberto Salemi
NA
146
142.2k
[WPF] Use IValueConverter but hide the value in cell
Jan 22 2015 9:34 AM
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:
<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#
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.
Reply
Answers (
5
)
Selection Mode in Datagrid in WPF
saving a mesh in wpf