title: Highlight the Activated Button WPF
body: <p>I have a wpf form that is called by a static method in much the same way as <code>MessageBox.Show()</code>; the button layout is defined in the method, and can be customised, within certain parameters. Each button is added with a style that is <code>BasedOn</code> a central style.</p>
  
  <p>Part of this style is a trigger that highlights the default button, so the user knows what will happen if they press <code>enter</code>. However, if the user presses tab a few times, there is a little dotted border that moves into each of the buttons in turn and then <em>this</em> is the button they will get when they press enter. I would like my highlight to start on the default button but follow this... ?focus? around if the user chooses to tab between the buttons.</p>
  
  <p>I had thought that the property to trigger on in the <code>&lt;ControlTemple.Triggers&gt;</code> would be <code>IsFocused</code>, but this does not seem to behave as I expected - here is a snippet of my xaml code as it stands:</p>
  
  <pre><code>&lt;!--....--&gt;
     &lt;Setter Property="Template"&gt;
          &lt;Setter.Value&gt;
              &lt;ControlTemplate TargetType="Button"&gt;
                  &lt;Border x:Name="border" 
                          BorderThickness="1"
                          Padding="0" 
                          BorderBrush="WhiteSmoke" 
                          CornerRadius="2" 
                          Background="{TemplateBinding Background}"&gt;
                      &lt;ContentPresenter x:Name="Contents" HorizontalAlignment="Center" VerticalAlignment="Center" RecognizesAccessKey="True"/&gt;
                  &lt;/Border&gt;
                  &lt;ControlTemplate.Triggers&gt;
                      &lt;Trigger Property="IsPressed" Value="true"&gt;
                          &lt;Setter Property="RenderTransform" TargetName="Contents"&gt;
                              &lt;Setter.Value&gt;
                                  &lt;TranslateTransform X="0" Y="2"/&gt;
                              &lt;/Setter.Value&gt;
                          &lt;/Setter&gt;
                      &lt;/Trigger&gt;
                      &lt;Trigger Property="IsDefault" Value="true"&gt;
                          &lt;Setter Property="BorderThickness" TargetName="border" Value="3"/&gt;
                          &lt;Setter Property="BorderBrush" TargetName="border" Value="White"/&gt;
                      &lt;/Trigger&gt;
                      &lt;Trigger Property="IsFocused" Value="True"&gt;
                          &lt;Setter Property="IsDefault" Value="True"/&gt;
                      &lt;/Trigger&gt;
                      &lt;Trigger Property="IsFocused" Value="False"&gt;
                          &lt;Setter Property="IsDefault" Value="False"/&gt;
                      &lt;/Trigger&gt;
                  &lt;/ControlTemplate.Triggers&gt;
              &lt;/ControlTemplate&gt;
          &lt;/Setter.Value&gt;
      &lt;/Setter&gt;
  &lt;!--....--&gt;
  </code></pre>
  
  <p>I thought that the focus would set the default when it triggered, and this would cause the highlight (3px white border) to show as the user pressed tab.</p>
  
  <p>What is the property that changes when the user presses tab (and/or why is it not responding for me?)</p>
  
  <p>-------------- ************ EDIT ************-------------</p>
  
  <p>Attempting to add lines to the code behind to add triggers directly. The foreach loop tracks through a list of custom class items that are basically slightly modified buttons; the <code>b.Style</code> is of type Style, but is looked up from some resources</p>
  
  <pre><code>        foreach (Buttons b in buttonList)
          {
              if (i &gt; 0)
              {
                  totalWidthNeeded = totalWidthNeeded + gapPixels;
                  ColumnDefinition gapColumn = new ColumnDefinition();
                  gapColumn.Width = gapWidth;
                  ButtonRowGrid.ColumnDefinitions.Add(gapColumn);
                  i++;
              }
  
              Button thisButton = new Button();
  
              var setter = new Setter() { Property = Button.IsDefaultProperty, Value = true};
              var trigger = new Trigger() { Property = Button.IsFocusedProperty, Value=true, Setters = { setter } };
  
              b.Style.Triggers.Add(trigger);
  
              thisButton.Style = b.Style;
  </code></pre>
  
  <p>Sadly, this code does not make a trigger that has a visible effect from the IsDefault trigger shown in the xaml above (I have removed the two IsFocused triggers).</p>