|
<local:CellStyleConverter x:Key="cellStyleConverter"/>
<syncfusion:GridTextColumn MappingName="Symbol" HeaderText="Column A" TextAlignment="Left" >
<syncfusion:GridTextColumn.CellStyle>
<Style TargetType="syncfusion:GridCell">
<!--Below code is for applying style using Triggers-->
<Style.Triggers>
<DataTrigger Binding="{Binding Path=Change,
Converter={StaticResource cellStyleConverter}}"
Value="True" >
<Setter Property="FontWeight" Value="Bold"/>
<Setter Property="Foreground" Value="Blue"/>
<Setter Property="Background" Value="Yellow"/>
</DataTrigger>
</Style.Triggers>
</Style>
</syncfusion:GridTextColumn.CellStyle>
</syncfusion:GridTextColumn>
<syncfusion:GridTextColumn MappingName="Change" TextAlignment="Center" HeaderText="Column B" />
public class CellStyleConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var changeValue = double.Parse(value.ToString()) >= 0;
return changeValue;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
} |
|
public class FontStyleConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (double.Parse(value.ToString()) >= 0)
return FontWeights.Bold;
return FontWeights.Normal;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
public class ForegroundConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (double.Parse(value.ToString()) >= 0)
return new SolidColorBrush(Colors.Blue);
return new SolidColorBrush(Colors.Black);
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
public class BackgroundConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (double.Parse(value.ToString()) >= 0)
return new SolidColorBrush(Colors.Yellow);
return new SolidColorBrush(Colors.Transparent);
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
<syncfusion:GridTextColumn MappingName="Symbol" HeaderText="Column A" TextAlignment="Left" >
<syncfusion:GridTextColumn.CellStyle>
<Style TargetType="syncfusion:GridCell">
<!--Below code is for applying style using converters-->
<Setter Property="FontWeight" Value="{Binding Change,
Converter={StaticResource fontStyleConverter}}" />
<Setter Property="Foreground" Value="{Binding Change,
Converter={StaticResource foreGroundConverter}}" />
<Setter Property="Background" Value="{Binding Change,
Converter={StaticResource backGroundConverter}}" />
</Style>
</syncfusion:GridTextColumn.CellStyle>
</syncfusion:GridTextColumn>
<syncfusion:GridTextColumn MappingName="Change" TextAlignment="Center" HeaderText="Column B" /> |