title: How does one make a transparent portion of a button clickable in WPF?
body: <p>I have a bunch of toolstrip buttons with transparent backgrounds in WPF. When the user mouses over the outside of the button, nothing happens, because that part of the button is transparent. Once the user mouses over one of the non-transparent areas of the button, the "hover" behavior changes the border and background color. The background is no longer transparent, so the hover behavior continues for a much larger area than before. I would like the transparent areas of the button to behave as if the button were non-transparent there.</p>
  
  <p>That is, now I have this behavior where the button is unselected despite the mouse being clearly inside the button area:</p>
  
  <p><img src="https://i.stack.imgur.com/zZgjh.png" alt="Bad Behavior"></p>
  
  <p>and I'm trying to get the button to be selected like this even if the user has not previously moused over the foreground "white" part of the button:</p>
  
  <p><img src="https://i.stack.imgur.com/39Qap.png" alt="Good Behavior"></p>
  
  <p>I tried setting <code>IsHitTestVisible</code> on the button itself, but that didn't seem to make any difference.</p>
  
  <p>Is there a way to ask WPF to consider the transparent areas of the button significant?</p>
  
  <p>XAML currently looks like this:</p>
  
  <pre><code>&lt;Button Style="{StaticResource MainToolstripButtonStyle}" Margin="5,0,0,0"
  ToolTip="{StaticResource OpenButtonText}"
  AutomationProperties.Name="{StaticResource OpenButtonText}"
  Command="{StaticResource Open}"
  Content="{StaticResource OpenIcon}" /&gt;
  
  &lt;Style x:Key="MainToolstripButtonStyle" TargetType="Button"&gt;
      &lt;Setter Property="Width" Value="24" /&gt;
      &lt;Setter Property="Height" Value="24" /&gt;
      &lt;Setter Property="Background" Value="{x:Null}" /&gt;
      &lt;Setter Property="Foreground" Value="White" /&gt;
      &lt;Setter Property="Padding" Value="0" /&gt;
      &lt;!-- If users want to use keyboard navigation, they use the menu instead. --&gt;
      &lt;Setter Property="IsTabStop" Value="False" /&gt;
      &lt;Setter Property="Focusable" Value="False"/&gt;
      &lt;Setter Property="Template"&gt;
          &lt;Setter.Value&gt;
              &lt;ControlTemplate TargetType="{x:Type Button}"&gt;
                  &lt;Border Name="Border"
                BorderThickness="1"
                BorderBrush="{x:Null}"&gt;
                      &lt;ContentPresenter HorizontalAlignment="Center"
                            VerticalAlignment="Center" 
                            RecognizesAccessKey="True" /&gt;
                  &lt;/Border&gt;
                  &lt;ControlTemplate.Triggers&gt;
                      &lt;!-- Low contrast triggers for selection / focus / enabled: --&gt;
                      &lt;MultiDataTrigger&gt;
                          &lt;MultiDataTrigger.Conditions&gt;
                              &lt;Condition Binding="{Binding Source={x:Static vvm:SystemParametersBindingTarget.Instance}, Path=HighContrast}" Value="False" /&gt;
                              &lt;Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=IsMouseOver}" Value="True" /&gt;
                              &lt;Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=IsEnabled}" Value="True" /&gt;
                          &lt;/MultiDataTrigger.Conditions&gt;
                          &lt;Setter TargetName="Border"
                    Property="Background"
                    Value="{StaticResource HotToolbarButtonBrush}" /&gt;
                          &lt;Setter TargetName="Border"
                    Property="BorderBrush"
                    Value="{StaticResource HotToolbarButtonBorderBrush}" /&gt;
                      &lt;/MultiDataTrigger&gt;
  
                      &lt;MultiDataTrigger&gt;
                          &lt;MultiDataTrigger.Conditions&gt;
                              &lt;Condition Binding="{Binding Source={x:Static vvm:SystemParametersBindingTarget.Instance}, Path=HighContrast}" Value="False" /&gt;
                              &lt;Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=IsEnabled}" Value="False" /&gt;
                          &lt;/MultiDataTrigger.Conditions&gt;
                          &lt;Setter Property="Foreground"
                    Value="{StaticResource DisabledToolbarButtonBrush}" /&gt;
                      &lt;/MultiDataTrigger&gt;
  
                      &lt;!-- High contrast triggers omitted --&gt;
                  &lt;/ControlTemplate.Triggers&gt;
              &lt;/ControlTemplate&gt;
          &lt;/Setter.Value&gt;
      &lt;/Setter&gt;
  &lt;/Style&gt;  
  </code></pre>