Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF: Making the entire "block" of a path clickable

Tags:

c#

path

wpf

I have a special ControlTemplate for some of my Buttons.

<ControlTemplate TargetType="{x:Type Button}">
    <Path Name="ThePath" Fill="White" Stretch="UniformToFill" 
          Width="12" Height="12" Stroke="White"
          StrokeThickness="4" 
          Data="M1.5,1.5 L10.5,10.5 M1.5,10.5 L10.5,1.5"/>
    <ControlTemplate.Triggers>
        <Trigger Property="IsFocused" Value="True">
            <Setter Property="Fill" Value="#afa" TargetName="ThePath"/>
        </Trigger>
    </ControlTemplate.Triggers>
</ControlTemplate>

This works fine, but since I'm using a Path (in this case, it's just shaped like a fat X), exactly the path is clickable, not the small space between the corners of the X. Is there any automagic thing I can use to make the entire "block" of the X clickable?

I've considered wrapping the path in a rectangular object, but I'd just like to make sure I'm not missing something trivial.

like image 679
Deniz Dogan Avatar asked Jan 30 '10 18:01

Deniz Dogan


1 Answers

Aviad P. is correct. This is what I do:

<Border Background="Transparent">
  <Path ... />
</Border>

This works because when "hit testing" to determine where a mouse click should be routed, the "Transparent" brush is considered as if it was a regular color.

like image 160
Ray Burns Avatar answered Nov 14 '22 11:11

Ray Burns