Hi,
1) If you want to apply a red foreground color only to the cell with Value equals "CC" in Column Firstname, you can use a DataTrigger in the "test1Template" :
2) I tried it with FontSize, and it worked :
1) If you want to apply a red foreground color only to the cell with Value equals "CC" in Column Firstname, you can use a DataTrigger in the "test1Template" :
<DataTemplate x:Key="test1Template">
<TextBlock x:Name="_textBlock"
Text="{Binding}"
Foreground="{Binding Foreground, Source={StaticResource View1}}"/>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding Path=.}"
Value="CC">
<Setter Property="Foreground"
Value="Red"
TargetName="_textBlock"/>
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
If you want to apply it to all the cells that contains "CC", you can use a converter in the binding of the DataTrigger to get them.2) I tried it with FontSize, and it worked :
<DataTemplate x:Key="test1Template">
<TextBlock Text="{Binding}"
Foreground="{Binding Foreground, Source={StaticResource View1}}"
FontSize="{Binding FontSize, Source={StaticResource View1}}"/>
</DataTemplate>
public class MyViewModel : DependencyObject
{
//.....
public double FontSize
{
get
{
return ( double )GetValue( FontSizeProperty );
}
set
{
SetValue( FontSizeProperty, value );
}
}
public static readonly DependencyProperty FontSizeProperty = DependencyProperty.Register( "FontSize", typeof( double ), typeof( MyViewModel ),
new UIPropertyMetadata( 11d ) );
}
private void Button_Click( object sender, RoutedEventArgs e )
{
MyViewModel viewModel = this.Resources[ "View1" ] as MyViewModel;
if( viewModel != null )
{
viewModel.Foreground = new SolidColorBrush(Colors.Yellow);
viewModel.FontSize = 20d;
}
}