I've written a date control that's used for displaying days for a variable range laid out by month. The days are designed to display a two-letter code for either the AM, PM or entire day and may have their backgrounds set to specific colours, for example:
To get the days to be evenly spaced and to match the day number columns I've used a UniformGrid contained in a Stackpanel:
<StackPanel DockPanel.Dock="Bottom" Orientation="Horizontal">
<ItemsControl Name="cal" ItemsSource="{Binding Days}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Rows="13" Columns="32" Margin="0,0,1,5" Width="1158" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<local:ucYearViewDay/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
The days are each a user control (that impliments INotifyPropertyChanged
) I've designed that support showing AM, PM or full day codes. The days are then added to the ObservableCollection that the date control is bound to.
The Problem
All of the above set up work is done from calls in the constructor, when Form.Show()
is called it takes about 10-12 seconds to render the form.
Research
I've spent a bit of time reading up on what I can do to speed this up but I don't seem to be able to find anything to help. I've tried setting the ItemsControl to make use of Virtualizing as suggested in this post but that's made no difference - as I understand I'd only get performance gains this way if I used a lot of scrolling and my control does not scroll. There is a guide on MSDN about improving WPF performance which I've been looking at, specifically the section on data binding but I didn't find anything that helped much.
Based on what I've said, are there any other techniques that I could employ to speed things up? I suppose I could do away with the binding and write to the controls directly but this would be a last resort.