title: Changing ControlTemplate when button clicked Wpf
body: <p>I have the following simple XAML file:</p>
  
  <pre><code>&lt;Window 
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
         Title="WpfApplication4" Height="300" Width="300"&gt;
      &lt;Window.Resources&gt;
          &lt;ControlTemplate x:Key="simpleErrorTemplate"&gt;
              &lt;TextBox Margin="10,10,10,5" TextWrapping="Wrap" VerticalScrollBarVisibility="Auto" Text="T1" /&gt;
          &lt;/ControlTemplate&gt;
          &lt;ControlTemplate x:Key="detailedErrorTemplate"&gt;
              &lt;StackPanel&gt;
                  &lt;TextBox Margin="10,10,10,5" TextWrapping="Wrap" VerticalScrollBarVisibility="Auto" Text="T2" /&gt;
                  &lt;TextBox Margin="10,10,10,5" TextWrapping="Wrap" VerticalScrollBarVisibility="Auto" Text="T3" /&gt;
                  &lt;TextBox Margin="10,10,10,5" TextWrapping="Wrap" VerticalScrollBarVisibility="Auto" Text="T4" /&gt;
              &lt;/StackPanel&gt;
          &lt;/ControlTemplate&gt;
      &lt;/Window.Resources&gt;
      &lt;Grid&gt;
          &lt;ContentControl&gt;
              &lt;ContentControl.Style&gt;
                  &lt;Style TargetType="ContentControl"&gt;
                      &lt;Setter Property="Template"
                          Value="{StaticResource simpleErrorTemplate}"/&gt;
                      &lt;Style.Triggers&gt;
                          &lt;DataTrigger Binding="{Binding ElementName=Button,Path=IsPressed}" Value="True"&gt;
                              &lt;Setter Property="Template" Value="{StaticResource detailedErrorTemplate}"/&gt;
                          &lt;/DataTrigger&gt;
                      &lt;/Style.Triggers&gt;
                  &lt;/Style&gt;
              &lt;/ContentControl.Style&gt;
          &lt;/ContentControl&gt;
          &lt;Button x:Name="Button" Content="Button" Height="40" Width="129" Margin="88,5,76,5" Grid.Row="1" Click="Button_Click1"/&gt;
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>What it does is that it changes the template when the button is pressed. 
  However, I want it to happen once I clicked, without the need of holding it pressed.</p>
  
  <p>1) Is there any trigger from the click style so the moment I clicked it will call the trigger?</p>
  
  <p>2) In the code-behind file, I had like it to run a function the moment I clicked the button and only afterwards to change the template since it is using data from the first template. </p>
  
  <pre><code>import wpf
  
  from System.Windows import Application, Window
  from scores import score
  
  class MyWindow(Window):
      def __init__(self):
          self.ui = wpf.LoadComponent(self, 'WpfApplication1.xaml')
  
      def Button_Click1(self, sender, e):
          x = score(name)
  
  if __name__ == '__main__':
      Application().Run(MyWindow())
  </code></pre>
  
  <p>So eventually my goal is to click Button, to calculate the function score and only then to change the template.</p>
  
  <p>Thank you for the help.</p>