Hello,
Welcome to Microsoft Q&A!
If you want to modify the foreground of each textblock, it's better to use Binding. You can declare a SolidColorBrush property in your Classdatah1 model which you will use to bind to the foreground of the textblock. If the three textblocks use the same foreground, you just need to declare a property, but if the three textblocks uses three different foregrounds, you need to declare three properties to bind with them. I take the first case as an example, suppose they always have the same foreground color.
.cs:
public class Classdatah1 : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged = delegate { };
......
private SolidColorBrush foregroundColor;
public SolidColorBrush ForegroundColor {
get {
return foregroundColor;
}
set {
foregroundColor = value;
OnPropertyChanged();
}
}
public void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
.xaml:
<TextBlock x:Name="cvd" Grid.Column="0" Text="{x:Bind Path=civildate}" Margin="12,6,0,0" Foreground="{x:Bind ForegroundColor,Mode=OneWay}"/>
<TextBlock x:Name="hwd" Grid.Column="1" Grid.Row="0" Text="{x:Bind Path=hwholedate}" Margin="50,6,0,0" Foreground="{x:Bind ForegroundColor,Mode=OneWay}" />
<TextBlock x:Name="np" Grid.Column="2" Grid.Row="0" Text="{x:Bind Path=namep}" Margin="290,6,0,0" Foreground="{x:Bind ForegroundColor,Mode=OneWay}" />
Suppose you want to change the foreground color when you click an item,
private void Dgvresult_ItemClick(object sender, ItemClickEventArgs e)
{
Classdatah1 model = e.ClickedItem as Classdatah1;
model.ForegroundColor = new SolidColorBrush(Colors.Red);
}