Reusing visual tree when moving items between two ItemControls

55 views Asked by At

I have two ObservableCollections in my ViewModel. Both of same generic type. Window has two ItemsControls each with ItemsSource bound on its own ObservableCollection from ViewModel. Both use same same ItemTemplate. This ItemTemplate is very complex user control. It's all done by the book.

In some cases, I move item from one collection to another. UI updates correctly. However, as control is complex, it needs about 1-2sec to render when it is recreated in new ItemsControl. And since this happens on drag and drop operation, it is not user friendly.

What I would like to do is to somehow preserve existing instance of ItemTemplate from source ItemsControl and reuse it in destination. I don't know if it is even possible, I couldn't find anything about it online.

I believe setup is fairly simple, but if needed I'll write some simplified version of code (I can't share the real code).

Thanks for any help.

1

There are 1 answers

4
mm8 On

What I would like to do is to somehow preserve existing instance of ItemTemplate from source ItemsControl and reuse it in destination. I don't know if it is even possible, I couldn't find anything about it online.

I am afraid it is not. When you disconnect an element from the visual tree and then add it back to a different parent element at a later stage, all elements that make up the control will be re-rendered.