views:

665

answers:

3

I'm writing a WPF desktop application and have a view that needs to look like a calendar. I only need to show four weeks (fixed). Each week will have a list of items (probably represented with a ListView). I'm debating between two approaches:

  1. Using layout controls - a Grid control where each "cell" contains a ListView

  2. Using a ListView + GridView and then customizing the style to look more like a calendar

In my opinion, the layout controls would be easier to implement but something about it feels dirty. I would essentially be hard-coding 28 cells each containing a ListView. But again, it would be simple.

I'm thinking the ListView/GridView would be more elegant, but I still need to create a ListView for each cell and then I have to figure out how to style the control in such a way that it looks more like a calendar and less like a table.

Thoughts?

+1  A: 

You could use a ListBox, with a UniformGrid. That would take care of building the base layout. With a little triggering on the current month to implement the change of style when the displayed day is not in the current month.

Then, each day can have a ListView or ListBox as part of its template, for displaying tasks/meetings/whatever.

The whole thing would bind to a collection of objects that represents the "days" and their content.

ListBox is usually a good bet for the base of an ItemsControl.

You should also have a look at how the Calendar control is built in WPF, it might help give you some ideas.

Denis Troller
Oh, I didn't know there was a built-in control. I would prefer to go that route if it is readily available. Are you talking about the date-picker or a larger sized calendar?
j0rd4n
I am talking about the Calendar part of the DatePicker (isn't it a standalone control as well ? maybe not).It will not fit your bill right away, but you might get something out of it, even if it's just insight on how to write Custom Controls in WPF.
Denis Troller
+1  A: 

Perhaps, the following example can help you: http://www.codeproject.com/KB/WPF/WPFOutlookCalendar.aspx

Tom Deleu
+1  A: 

Take a look to the source of Silverlight Toolkit it might work in WPF

Nicolas Dorier