WPF Figure on ListBox

In the created ListBox CustomControl, I need to draw lines connecting the ListBoxItems that are laid out in the Canvas ItemsPanel.
I can achieve this by having a ListBoxLines: UIElement class that does drawing in OnRender and then includes this object in its ListBox ControlTemplate (but for this I need to pass the contents of the list to this class ...)

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

I'm just wondering if there is an easier way. I'd really just like to add my drawing code directly to my ListBox class class, but if I do, it seems to draw UNDER on the white background of the listbox canvas.
Is there any way to custom list display directly in my derived list class?
EDIT: The motivation for this question is a custom control to display nodes and links between wireless networks, as shown in the figure below: enter image description here EDIT: Extra problem: OnRender code for ListBoxLines (node ​​links) is cached - how do I get this to redraw when dragging a node? Ideally, I want to create a cache with all the lines except for dragging nodes at the moment and only redraw by dragging the lines on the node - not sure how to do this.

+4
source share
1 answer

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


Personally, I would not have implemented such a control as I know from previous experience that this is not an easy task. In the last two three times, when I needed a graphical representation, I used mid-range solutions.

The middleware argument is a simple example:

  • This will save you significant development time.
  • You will get results faster, allowing you to focus on your specific requirements.
  • Even if you choose a commercial provider, saving time is equal to money.

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

I used both products for studio applications (internal, but released as if the users were customers).

...

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


Note that you like the ListBox selection part - did you know that the selection functionality is actually provided by the Selector base class?

+2
source

All Articles