Solved

Wpf  Datagrid  Row Colors

Posted on 2015-02-14
3
272 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:ADITYA RAO
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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:ADITYA RAO
ID: 40627403
Please  give  me  some  time  to  implement  this,I  am  very  busy  with  some other  task
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

710 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