What's the best control to use to design a outlook like calendar in WPF
In one of our project, we would like to have a calendar control that would look like Outlook calender in week mode, meaning one line per day for 7 days at a time. In this calendar we would add resources(i.e. objects) for half-hour or more and those would appear on the calendar.
What would be the best control to use in WPF to design such a control and why ? I was thinking about a simple listview with a rather elaborated item template, but I was wondering if something simplier could also be used.
Thanks
Edit : I forgot to mention that I will most likely implement some kind of drag and drop to drag resources into the calendar and maybe, if time allow, to move within the calendar itself. However, I don't believe this will make much of a difference in the choice of control since I believe every control can be made droppable.
Edit : Here is what I have so far :
<ItemsControl x:Name="ICPlanification" Grid.Column="1">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="20" />
<RowDefinition Height="20" />
<RowDefinition Height="20" />
<RowDefinition Height="20" />
</Grid.RowDefinitions>
</Grid>
</ItemsPanelTemplate>
开发者_JS百科 </ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border Grid.Row="{Binding GridRow}" Grid.RowSpan="{Binding ColSpan}" Grid.Column="{Binding GridCol}" Grid.ColumnSpan="{Binding ColSpan}" CornerRadius="0" BorderBrush="White" BorderThickness="1" Background="{Binding ColorBackground}" Panel.ZIndex="{Binding ZIndex}">
<TextBlock TextWrapping="Wrap" Text="{Binding Description}" ></TextBlock>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
I though this would work, but all items are put into the first row and column, making me thing it's impossible to put a grid into the ItemPanal.
And before anyone ask, yes, the GridRol and GridCol variable have the right values in my list.
While looking at some forums, I found something out and it worked!
<ItemsControl.Resources>
<Style TargetType="{x:Type ContentPresenter}">
<Setter Property="Grid.Column" Value="{Binding Path=Column}" />
<Setter Property="Grid.Row" Value="{Binding Path=Row}" />
</Style>
</ItemsControl.Resources
Here is the explanation that he gave :
"The problem that everyone is running into the the Grid and the dynamic binding of Row and Column is that the ItemsControl wraps each item in a ContentPresenter so the Grid.Row and Grid.Column binding in the DataTemplate are ignored and since the Grid.Row and Grid.Column properties on the generated ContentPresenter are not set then each item is positioned ontop of each other at column 0, row 0. You can get around this by setting the below style on the ItemsControl."
It depends on your how your DataObjects look.
If you have a List<Day>[7]
of Days, and each Day has a List<TimeFrame>[48]
property of the TimeFrames, I would use an ItemsControl
with the ItemsPanelTemplate
being a StackPanel Orientation=Horizontal
, then the ItemTemplate
being a regular vertical StackPanel
containing a header for Day of Week, and ListBox
for the different TimeFrames.
If you simply have a List<Reminder>
and Reminders
have Day
and Time
properties, than I would do an ItemsControl
with the ItemsPanelTemplate
being a Grid
and the ItemTemplate
being an object that binds Grid.Row
and Grid.Column
using a Converter to get the correct Day and TimeFrame spot in the Grid
If your project has the budget for external controls and you do not want to spent the time implementing this yourself then I suggest you take a look at Telerik's WPF Controls which include the schedule view control. Here's a link to a page that also contains a Demo.
精彩评论