NodePanel in Listbox


We have a NodeTemplate that consists of a list of items with a DataTemplate containing all my ports and node linkable bits. When this list is an ItemsControl this works fine, I can select an item and drag a link to another node in my diagram. Similarly, I can drag a link from other items and drop it on my list item with no problems.

However, we now need the extra functionality that a ListBox provides and this seems to have introduced a problem. I can still drag a link from another node and drop it on my list items. But the ListBox prevents me selecting an item to drag a link from it as the ListBox handles the selection differently.

I appreciate this is probably more a WPF question than GoDiagram but I just wondered if you had encountered this issue before and had a possible solution.

I don’t have an answer for you, but you can see what we did in the Dynamic Ports sample where there are four ListBoxes on each node, one on each side.

The problem was that the default mouse-down behavior of ListBoxItems wasn’t what we wanted, so we had to define a subclass of ListBoxItem. Then we had to define a subclass of ListBox in order to make use of the ListBoxItem subclass.

However, I’m not sure exactly what you want to do, so that code and XAML might not be what you want to do. I would definitely look carefully at the various standard templates associated with ListBox.

Ok I’ll have a look in that example. It sounds like that’s the sort of thing I need, thanks.

Yep, that was spot on. Thanks again Walter.

Ok Walter it seems I may have been a little premature. I have used your Dynamic Ports example, but all this has done is made my ListBox no longer have the ListBox functionality I require.

public class CustomListBox : ListBox <br /> { <br /> protected override DependencyObject GetContainerForItemOverride() <br /> { <br /> return new CustomListBoxItem(); <br /> } <br /> } <br /> <br /> public class CustomListBoxItem : ListBoxItem <br /> { <br /> protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e) <br /> { <br /> base.OnMouseLeftButtonDown(e); <br /> e.Handled = false; <br /> } <br /> } <br />

So now, when I click on a ListBox item, I can drag a link from/to it but the ListBox item is no longer selected. This means that I can’t delete the item. Is there a way that I can override something in your code so that it requires the shift key to be pressed when dragging a link, a custom dragging tool for example?

Right, I’ve gone back to the drawing board on this one and implemented it differently. I’m now using an ItemsControl and having a delete button on each item in the list.

Apologies for wasting your time.