How to change text color of a gridViewColumn in WPF?

nizam uddin picture nizam uddin · Apr 17, 2014 · Viewed 9.6k times · Source

I have A listView In which i want to show items from dataBase. It works fine, But i want to see the items shown in cells as white in a purple listview, How to do it ?

<ListView Margin="127,114,227,357" x:Name="lv" Background="purple" >
    <ListView.View>
       <GridView>
          <GridViewColumn DisplayMemberBinding="{Binding Path=FirstName}" Header="First Name" Width="100"  />
         <GridViewColumn DisplayMemberBinding="{Binding Path=LastName}" Header="Last Name" Width="100" />
         <GridViewColumn DisplayMemberBinding="{Binding Path=Email}" Header="Email" Width="100" />
       <GridViewColumn DisplayMemberBinding="{Binding Path=Password}" Header=" Password" Width="100" />
       <GridViewColumn DisplayMemberBinding="{Binding Path=Address}" Header="Address" Width="100" />

      </GridView>
   </ListView.View>

Answer

Sajeetharan picture Sajeetharan · Apr 17, 2014

You need to use DataTemplate and change the text Foreground property, this is one sample for GridViewColumn.

Check on DataTemplate here: Data Templating Overview

<GridViewColumn  DisplayMemberBinding="{Binding Path=FirstName}" Header="First Name" Width="1000">
    <GridViewColumn.CellTemplate>
       <DataTemplate>
            <TextBlock x:Name="Txt" Text="{Binding FirstName}" Foreground="Purple" />                 
       </DataTemplate>
    </GridViewColumn.CellTemplate>
</GridViewColumn>