Solved

Wpf  Datagrid  Row Colors

Posted on 2015-02-14
3
220 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
Comment Utility
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
Comment Utility
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
Comment Utility
Please  give  me  some  time  to  implement  this,I  am  very  busy  with  some other  task
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
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 video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

763 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

10 Experts available now in Live!

Get 1:1 Help Now