Display several hundreds of rectangles RRS feed

  • Question

  • Hi, 

    I'm working on an application which supervises different equipments (machines)

    I would like to build a window that shows the timeline of events, for each equipment, by drawing a colored rectangle whose width corresponds to the duration of the event. See picture. In real life, all rectangles are different (different width and different color).

    Over a time period of 8 to 12 hours, there might be several hundreds of such rectangles. I am concerned with the response time of that screen.

    What is the best way (best performance) of obtaining such a result ?

     - The Rectangle shape ?

     - The RectangleGeometry ?

     - The DrawRectangle ?

     - something else ?


    • Edited by Sygrien Wednesday, November 21, 2018 3:13 PM
    Wednesday, November 21, 2018 2:47 PM

All replies

  • Best performance would be relatively hard to implement but draw it using writeablebitmap.

    This is extremely fast.

    I calculate and build a picture 1155 x 805 in  about 29ms in our app.

    Easier to implement would be to make those rectangles in an itemscontrol.

    Make the stackpanel which is it's itemspanel orientate horizontally.

    Bind the fill for colour. It's a brush.

    You could also bind or set the outline to a different brush.

    And bind the width of the itemcontainer using a style.

           <Style TargetType="ContentPresenter">
                 <Setter Property="Width" Value="{Binding YourWidth">

    You can then bind an observablecollection of viewmodels to the itemscontrol.

    Each would expose public properties for YourWidth and YourFillBrush

    Implement inotifypropertychanged on this vm.

    Hope that helps.

    Technet articles: WPF: Layout Lab; All my Technet Articles

    Wednesday, November 21, 2018 4:11 PM
  • Thanks Andy,

    I will need some time to test this. Will let you know.

    Thanks again.

    Thursday, November 22, 2018 12:26 PM
  • I would not expect templating several hundred viewmodels into rectangles to be a problem on even a low power business pc.

    I've done much more complicated stuff with this sort of technique.


    Hope that helps.

    Technet articles: WPF: Layout Lab; All my Technet Articles

    Thursday, November 22, 2018 4:55 PM