title: WPF: swapping out control templates increases performance, efficiency?
body: <p>I have a general question about WPF performance. We have a relatively simple forms application. Some team members believe that redesigning the templates for basic controls will improve performance and maintainability. One preferred technique is to create multiple control templates for a control, and swap them out with triggers. The belief is that a smaller visual tree will be more performant.</p>
  
  <p>For example, the checkbox template is now two templates, one checked and one unchecked:</p>
  
  <pre><code>    &lt;ControlTemplate x:Key="CheckedCheckBoxCT" TargetType="{x:Type CheckBox}"&gt;
      &lt;Grid x:Name="gLayoutRoot" VerticalAlignment="Center" HorizontalAlignment="Left"&gt;
          &lt;Grid.ColumnDefinitions&gt;
              &lt;ColumnDefinition x:Name="colCheck" /&gt;
              &lt;ColumnDefinition x:Name="colContentLabel" /&gt;
          &lt;/Grid.ColumnDefinitions&gt;
          &lt;Rectangle x:Name="rectOuter" 
                  Stroke="{TemplateBinding BorderBrush}" 
                  StrokeThickness="0.5" 
                  Fill="White" 
                  Width="13" Height="13"   /&gt;
          &lt;Rectangle x:Name="rectInner" 
                  Stroke="{TemplateBinding OpacityMask}" 
                  StrokeThickness="0.5" 
                  Width="9" Height="9" 
                  Fill="{TemplateBinding Background}"/&gt;
          &lt;Path x:Name="CheckMark"                
                    Data="{DynamicResource CheckSymbol}" 
                    Fill="{TemplateBinding Foreground}"/&gt;
          &lt;ContentPresenter x:Name="cpContent" /&gt;
      &lt;/Grid&gt;
  &lt;/ControlTemplate&gt;
  </code></pre>
  
  <p>and then the unchecked (note there's no path element):</p>
  
  <pre><code>    &lt;ControlTemplate x:Key="CheckBoxCT" TargetType="{x:Type CheckBox}"&gt;
      &lt;Grid x:Name="gLayoutRoot" 
             VerticalAlignment="Center" 
            HorizontalAlignment="Left"&gt;
          &lt;Grid.ColumnDefinitions&gt;
              &lt;ColumnDefinition x:Name="colCheck" /&gt;
              &lt;ColumnDefinition x:Name="colContentLabel" /&gt;
          &lt;/Grid.ColumnDefinitions&gt;
          &lt;Rectangle x:Name="rectOuter" 
                     Stroke="{TemplateBinding BorderBrush}" 
                     StrokeThickness="0.5" 
                     Fill="White" 
                     Width="13" Height="13"   /&gt;
          &lt;Rectangle x:Name="rectInner" 
                     Stroke="{TemplateBinding OpacityMask}" 
                     StrokeThickness="0.5" 
                     Fill="{TemplateBinding Background}" 
                     Width="9" Height="9" /&gt;
          &lt;ContentPresenter x:Name="cpContent" 
                      Margin="5,0,0,0" 
                      VerticalAlignment="Center" 
                      Grid.Column="1" /&gt;
      &lt;/Grid&gt;
  &lt;/ControlTemplate&gt;
  </code></pre>
  
  <p>There is a similar discussion on making a read-only textbox with selectable text, using triggers to swap out a textblock (that you can't select text from) with a textbox.</p>
  
  <p>Does this really improve performance to any appreciable degree? With the checkbox, would a trigger to show/hide the check, instead of two different control templates, be about the same, or better?</p>
  
  <p>I really don't care, but it seems like there's a lot of complexity added for not much gain. I was curious what others' opinions were, esp. if based on objective experience. (You can see I don't care enough to set up some sample apps and test performance on them. :) )</p>
  
  <p>Thanks!</p>