0

I've put together a scheduling application similar in style to that found in outlook, however it can show the schedules of multiple people. I have written a user control, basically a Border with gradient filled background & TextBlock. One of these controls are added to a Canvas at a set location for every appointment. The trouble is, I will have multiple users, with multiple appointments and may need to display 1000 or so appointments at a time. Initially, it takes an absolute age to instantiate all of these objects, however, I can live with this.

Unfortunately, the big problem arises when I try to scroll through the appointments. I have a couple of buttons to scroll left and right and upon clicking these, the UserControls' Left position are moved left or right a certain number of pixels - it can take several seconds between clicking a button and repainting(I also tried with labels just to test, but it was the same).

I guess the real question here is how to implement an interface, showing hundreds of controls with adequate performance and if this isn't achievable, how would I approach such an UI.

Chico
  • 309
  • 3
  • 10
  • 5
    I'm assuming the user can't look at 1000's of these events at a time, why not just load what the user can see? This is a feature of Virtualizing stack panels (used in lists): https://msdn.microsoft.com/en-us/library/system.windows.controls.virtualizingstackpanel%28v=vs.110%29.aspx – Ron Beyer May 11 '15 at 17:30
  • Or (as an alternative) just manually paint (render) the appointments in a single control. There's tons of examples for wpf about this topic. It gets harder when you want to interact with all of them but also doable. Hint: A starting point would be WPF's [OnRender](https://msdn.microsoft.com/de-de/library/system.windows.uielement.onrender%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396). – Roemer May 11 '15 at 18:30

2 Answers2

0

One possible option is a TextBlock CustomControl. You can get the exact same style as you have in your usercontrol but with a somewhat faster loading time.

CJK
  • 952
  • 2
  • 10
  • 22
0

Without a good, minimal, complete code example that reliably reproduces the problem, it will be difficult if not impossible to completely understand the performance problem you are having, never mind provide a solution.

That said, from your description it sounds like you are really looking to present the user with some type of ItemsControl, such as ListBox or ListView (a specialization of ListBox). In an ItemsControl, you can specify an ItemTemplate that defines how each item in the list will appear; this is analogous to the UserControl you apparently are using now.

I believe it's likely it will work fine just with that change alone. I.e. define your per-item visual as a DataTemplate instead of a UserControl, and set the ItemTemplate property of e.g. your ListBox to that template, then just bind your collection of appointment objects to the ListBox.ItemsSource property.

Note that the ListBox class already defaults to using VirtualizingStackPanel in its ItemsPanel template. So you should have no performance problems at all with this approach if you use ListBox.

If you want to use a different ItemsControl or create a custom one, you may or may not find that you need to use a virtualizing panel object explicitly (such as the VirtualizingStackPanel that ListBox uses). With just 1000 items in the list, even a non-virtualized panel may be fine, but if not then even when not using ListBox, you can always specify it explicitly.

Community
  • 1
  • 1
Peter Duniho
  • 68,759
  • 7
  • 102
  • 136