Solved

Wpf  Datagrid  Row Colors

Posted on 2015-02-14
3
284 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

628 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