title: How To improve wpf user control performance?
body: <p>I have a usercontrol, and when I have lots of that in a window, it takes long time to get loaded.
  Will it get better if I change it to a customcontrol or maybe a <code>DataTemplate</code> with a class and attached properties?
  any ideas would be greatly appreciated.</p>
  
  <p><strong>Edited:</strong></p>
  
  <p>this is my control:</p>
  
  <pre><code>&lt;UserControl 
      x:Class="Pouyansoft.WPF.MVVM.Control.Common.View.DataGridSelectorControl"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
      x:Name="dataGridSelector"
      xmlns:sys="clr-namespace:System;assembly=mscorlib"
      mc:Ignorable="d" &gt;
  &lt;UserControl.Resources&gt;
      &lt;CollectionViewSource Source="{Binding DataCollection.Source}" x:Key="theSource"/&gt;
      &lt;Style x:Key="DataGridColumnHeaderStyle1" TargetType="{x:Type DataGridColumnHeader}"&gt;
          &lt;Setter Property="Template"&gt;
              &lt;Setter.Value&gt;
                  &lt;ControlTemplate TargetType="{x:Type DataGridColumnHeader}"&gt;
                      &lt;Grid VerticalAlignment="Center" HorizontalAlignment="Stretch"&gt;
                          &lt;Grid.RowDefinitions&gt;
                              &lt;RowDefinition Height="*"/&gt;
                              &lt;RowDefinition Height="*"/&gt;
                          &lt;/Grid.RowDefinitions&gt;
                          &lt;TextBlock Grid.Row="0" Text="{TemplateBinding Content}" 
                                     HorizontalAlignment="Center" /&gt;
                          &lt;TextBox x:Name="txtSearch" Grid.Row="1"  HorizontalAlignment="Stretch"  
                                   BorderThickness="1" TextChanged="TextBox_TextChanged" /&gt;
                      &lt;/Grid&gt;
                  &lt;/ControlTemplate&gt;
              &lt;/Setter.Value&gt;
          &lt;/Setter&gt;
      &lt;/Style&gt;
  &lt;/UserControl.Resources&gt;
  
  &lt;Grid&gt;       
     &lt;DataGrid x:Name="grd" 
               ItemsSource="{Binding Source={StaticResource theSource}}" 
               AutoGenerateColumns="False"
               ColumnHeaderStyle="{DynamicResource DataGridColumnHeaderStyle1}"   
               PreviewKeyDown="grd_PreviewKeyDown"
               SelectedIndex="{Binding SelectedIndex}"
               behavior:MouseDoubleClick.Command="{Binding MouseDoubleClickCommand}" 
               PreviewMouseLeftButtonUp="grid1_PreviewMouseLeftButtonUp"  
               GridLinesVisibility="Vertical"&gt;
      &lt;/DataGrid&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p></p>
  
  <p>and some code in the code behind.(and actually  all the other control has the same behavior)</p>