Solved

Wpf  Datagrid  Row Colors

Posted on 2015-02-14
3
243 Views
Last Modified: 2015-03-27
As I  am  going to  develop  a  new  project  by  extending  capabilities  of  previous  project which was  developed  in WPF,VC#. My  new  project  is  going  to  communicate  with  two  different  biomedical  instruments. From  instrument  I  will  read  results  and  save into database. From database  by  processing  results  I  will show  it  in different  formats  on  various forms as  per  domain  requirement. While  saving  results  in database  I  will  store  it   with  instrument  id.
Now  while  showing on  datagrid  I  have  to  display  results  in different  ForeColor  and  different  backcolor  of rows for two  different  instrument.I  have  searched  in  google   and I  have  just  known  that  coloring  rows  is possible  in  WPF. Now  Please  by  understanding  my  problem,can  any one  tell  me  syntax  or  tips. I  am  right  now  in  design  phase  for  my  project. So  tips  from  experts  will be  helpful  at  this  time. I  want  to  have  good  graphs  for  displaying  on  WPF,Is  there  any  good  cheap  resource  available  in  market? Please  suggest
0
Comment
Question by:enthurao
3 Comments
 
LVL 96

Accepted Solution

by:
Bob Learned earned 250 total points
ID: 40612140
You can set the AlternatingCount to 2, and then add a row style like this:

<DataGrid.RowStyle>
            <Style TargetType="{x:Type DataGridRow}">
                <Style.Triggers>
                    <Trigger Property="AlternationIndex" Value="0">
                        <Setter Property="Background" Value="White" />
                    </Trigger>
                    <Trigger Property="AlternationIndex" Value="1">
                        <Setter Property="Background" Value="SkyBlue" />
                    </Trigger>
                    <DataTrigger Binding="{Binding Path=Selectable}" Value="False">
                        <DataTrigger.Setters>
                            <Setter Property="Background" Value="Gainsboro" />
                        </DataTrigger.Setters>
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </DataGrid.RowStyle>

Open in new window

0
 
LVL 22

Assisted Solution

by:ambience
ambience earned 250 total points
ID: 40612483
There are several different ways to achieve that

1 - Use DataTrigger inside a DataTemplate to alter color, e.g. (especially useful when you already have a DataTemplate)

<DataTemplate.Triggers>
<DataTrigger Binding="{Binding Path=ItemType}" Value="Something">
<Setter Property="ListBoxItem.Foreground" Value="Red"></Setter>
</DataTrigger>
</DataTemplate.Triggers>

Open in new window


In your case, you may have to write a value converter to return the type of the Item (say its className) and use that as trigger value.

2 - DataTrigger can also be used inside a Style (as already shown).

3 - Use a StyleSelector that lets you change the entire Style of an item, without having to write a template

4 - Use different DataTemplates either declaratively or using TemplateSelector.
0
 

Author Comment

by:enthurao
ID: 40627403
Please  give  me  some  time  to  implement  this,I  am  very  busy  with  some other  task
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Export import database 4 51
Angular - break the dataset in chunks? 7 50
Reset asp.net login password 4 42
Web Form VB.Net  import CSV 4 36
In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now