开发者

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

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>
</ControlTemp开发者_运维知识库late>

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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜