Ricibob
Ricibob

Reputation: 7705

WPF Drawing on a ListBox

In a ListBox derived CustomControl I need to draw lines joining ListBoxItems that are layed out in a Canvas ItemsPanel.
I can achieve this by having class ListBoxLines : UIElement that does drawing in OnRender and then including that object in my ListBox ControlTemplate (but to do that I need to pipe the listbox contents to that class...)

<ControlTemplate TargetType="{x:Type p:NetworkVisualization}">  
    <Grid>  
        <p:ListBoxLines/>
        <ItemsPresenter/>
    </Grid>
</ControlTemplate>

Im just wondering if there is an easer way. Id really just like to add my draw code directly to my ListBox derived class but if I do that it seems to draw UNDER the listbox canvas white background.
Is there any way to to custom listbox drawing directly in my derived listbox class?
EDIT: The motivation for this question is a custom control to display nodes and linkstrengths of a wireless mesh network as in the image below:enter image description here EDIT: Additional issue: The OnRender code for ListBoxLines (the node links) is cached - how to force a redraw of this when a node is dragging? Ideally i want to build the cache with the all lines except for the currently dragging nodes lines and only redraw while dragging the lines to that node - not sure how to go about that.

Upvotes: 4

Views: 819

Answers (1)

Dennis
Dennis

Reputation: 20571

Thanks for updating the question - from the original description we were on completely different pages.


Personally I would not implement a control like this, as I know from prior experience that it is not easy task. In the last two three occasions where I have needed charting I have used middle-ware solutions.

The argument for middleware is an easy case to make:

  1. It will save you significant development time.
  2. You will get results quicker, allowing you focus on your specific requirements.
  3. Even if you choose a commercial provider, the time saved equates to money.

I recently evaluated charting middleware options for a project less than 5 months ago so I can tell your directly that for a WPF application the best libraries are:

I have used both products for studio applications (internal, however released as if the users were clients).

...

Take a look at the above solutions, come back with further questions (if any) and then if you still want to write your own I will at the very least point you in the direction and resources to do.


A side note, you say that you like the selection part of the ListBox - did you know that the selection functionality is actually supplied by the Selector base class?

Upvotes: 2

Related Questions