views:

556

answers:

2

Goal Develop a custom control which displays summary data for a specified week.

The data passed in would be as follows:

3rd May 2009        Customer A     $2000
4th May 2009        Customer A     $3900
6th May 2009        Customer B     $1900

The expected display would be

    3rd May      4th May        5th May        6th May
   Customer A   Customer A                    Customer B
    $2000        $1900                          $1900

As you can see the data is conditional based on the date.

Can items be databound based on a condition in WPF?

i.e. show summary when data source date == current items date

or should I just stick to coding this logic in C# behind?

----------------- Edit for Andy's questions --------------------

I can make it implement an interface but not a base class.

What I want to do is have the control showing 1 week from a year worth of dates this will be set via a property called current week.

Then when the known data source (see example table above) is passed in I want any day items in the control to pull their data from the data source if there is any, and if not then still show but just show the date.

The data would be a list of grid summary objects

public class GridSummary
{
     public DateTime SummaryDate;
     public Client Customer;
     public decimal Amount;
}
A: 

You can do this:

if(a)
    this.DataSource = a;
else
    this.DataSource = b;

I'm not sure that is what you meant though.

Are you doing your own rendering? or are you building your control off of the base controls? You maybe able to use nested controls to get what you want and you can conditionally control the nested controls.

Nate Bross
This is in WPF so essentially it will be a form of list control with a header and footer.
Peter
+1  A: 

If I understand you correctly, you want to display some tabular data in a list format. Is this correct?

What do you know about the data input? Is it guaranteed to implement an interface, or inherit from a base class? If the later, then I think that data templates are the way to go - create a data template for each possible type that you expect to be given, and for each set the TargetType to the type it should display. When you bind the data to the control, WPF will automatically chose the correct data template for each object in the collection.

If you can't know anything about the data coming in, how can you possibly know what to display, or how to display it? It seems like at a minimum there should be some things that must be known about the incoming data.

(It's possible I'm not understanding what you're trying to do - please clarify, and I'll see if I can help more.)

Update

It sounds like the data source for your control will be a list of GridSummary objects. If this is the case, then I think that you can use a CollectionViewSource as the data source instead (which basically wraps your collection of GridSummary objects), and subscribe to its Filter event. For each object that is passed in, compare the date to the week of the CurrentWeek property, and if the date is in that week accept it (the linked MSDN page has an example of this).

Andy
See the edit I made above and thanks for your time.
Peter
I had found this previously but wasn't sure of it.I understand what you are saying and I will have to do a little bit of extra code as each day would need an additional level of filtering over the week filter, but I understand the principle you're explaining.Thanks for the help!
Peter