Why using UserControl inside DataTemplate is slower than direct xaml?

I have code as this one:

  1. <ListBox ItemsSource="{Binding Items}">
  2. <ListBox.ItemTemplate>
  3. <DataTemplate DataType="{x:Type local:MyViewModel}">
  4. <!-- xaml is typed here directly -->
  5. <Border>
  6. ...
  7. </Border>
  8. </DataTemplate>
  9. </ListBox.ItemTemplate>
  10. </ListBox>

And xaml inside the DataTemplate is big (more than 200 lines).
I want to move xaml which is inside the DataTemplate into a separate UserControl to make it easier to edit and maintain. I do next:

  1. <ListBox ItemsSource="{Binding Items}">
  2. <ListBox.ItemTemplate>
  3. <DataTemplate DataType="{x:Type local:MyViewModel}">
  4. <!-- xaml is moved to separate UserControl -->
  5. <local:MyViewModelUserControl />
  6. </DataTemplate>
  7. </ListBox.ItemTemplate>
  8. </ListBox>

The issue I run into is that rendering/processing the second code (with UserControl) takes about 2 times longer than the 1st code. Any ideas how to deal with it?

NOTE: I’m moving not the ListBox, but the xaml which is inside the DataTemplate. The reason is not to reuse this code, but to minimize the main file where the ListBox is placed. Other thing is that I have several DataTemplates inside the ListBox (for several ViewModels) and the xaml is really huge. That’s why I want to move this xaml (which is inside the DataTemplate) to a separate control.

A1:
I know this is an old question, but I ran into this issue recently as well. There is significant overhead in creating user controls in WPF which seems to come from connecting a code-behind class file to the XAML. If all you are trying to do is move XAML to another location, simply define your DataTemplate in a ResourceDictionary in another file, and load it as a StaticResource. This will provide a few advantages:
(1) Ability to use x:Name for elements, which is not allowed in an inline DataTemplate.
(2) Performance. A DataTemplate with direct XAML is orders of magnitude faster than a UserControl in a DataTemplate.
(3) Cleanliness. You can define the DataTemplate wherever you like (a resource dictionary in the same file, near where you’re using it, a different file, etc.) and refer to it as a StaticResource.

A2:
You can simplify your “MyViewModelUserControl” - instead of inheriting from UserControl you can inherit directly from Border and do so in its XAML as well (Border instead of UserControl as a root element). That will give you the same performance as you had before, but you can keep it in a separate Control.