1

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>

nizam uddin
  • 341
  • 2
  • 6
  • 15

3 Answers3

5

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>
Steven Ackley
  • 593
  • 7
  • 31
Sajeetharan
  • 216,225
  • 63
  • 350
  • 396
  • iTHINK WHEN WE USE DataTemplate then we cant use setter and textblock both, and we dnt have to use DisplayMemberBinding={ Binding Path=FirstName}" in gridviewColumn. though we can use foreground property in Textblock...it works fine for me. – nizam uddin Apr 17 '14 at 10:43
  • ya thats what i have mentioned, please mark it as an answer if it has helped you – Sajeetharan Apr 17 '14 at 10:44
  • This doesn't work for me. I thought DisplayMemberBinding and CellTemplate were mutually exclusive? – Randall Deetz Jun 22 '18 at 17:29
  • Also doesn't work for me, the text colour does not change – pay Jan 08 '19 at 19:08
0

As per the accepted answer, in order for the TextBlock to remain binded and the Foreground color to change, the following worked for me:

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

and in my case I decided to create a property for the text color and bind to that

<GridViewColumn Header="First Name" Width="1000">
    <GridViewColumn.CellTemplate>
       <DataTemplate>
            <TextBlock x:Name="Txt" Text="{Binding Path=FirstName}" Foreground="{Binding Path=TextColor}" />                 
       </DataTemplate>
    </GridViewColumn.CellTemplate>
</GridViewColumn>
pay
  • 366
  • 3
  • 18
0

All wrong answers. You simply need to change GridView.ColumnHeaderTemplate property.

<ListView ItemsSource="{...}" Foreground="White" >
  <ListView.View>
    <GridView>
      <GridView.ColumnHeaderTemplate>
        <DataTemplate>
          <TextBlock Foreground="White" Text="{Binding}"/>
        </DataTemplate>
      </GridView.ColumnHeaderTemplate>
  <GridViewColumn  DisplayMemberBinding="{Binding Path=FirstName}" Header="First Name" Width="1000"/>
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 04 '22 at 22:16