سؤال

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>

هل كانت مفيدة؟

المحلول

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>

نصائح أخرى

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>

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"/>

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top