如何在UWP中使Region内的PATH可点击

问题描述

您好,我有一个用例,我需要绘制一个复杂的形状(此处为演示用半圆),这是我使用PATH Uwp类完成的,现在我需要在PATH区域内创建clickable(即用户应该能够单击使用PATH绘制的形状的覆盖区域)。这是XAML,任何人都有一个想法如何实现,然后请分享,将对您有所帮助。谢谢

<Canvas Width="300" Height="300" Background="DarkGray">
                <Path stroke="Black" Fill="Purple" strokeThickness="4" >
                    <Path.Data>
                        <PathGeometry>
                            <PathGeometry.figures>
                                <Pathfigure StartPoint="0,100">
                                    <Pathfigure.Segments>
                                        <ArcSegment     x:Name="UpperArcSegment"
                                                            IsLargeArc="True"
                                                            Size="20,20"
                                                            SweepDirection="Clockwise"                                            
                                                            Point="200,100" />                                       

                                    </Pathfigure.Segments>
                                </Pathfigure>
                            </PathGeometry.figures>
                        </PathGeometry>
                    </Path.Data>
                </Path>
            </Canvas>

enter image description here

解决方法

我可以使用按钮控件中的换行内容来做到这一点,那么任何人都有更好的方法,请分享。这只会使“路径部分”可点击。请确保将“路径填充属性”设置为任何颜色或透明

 <Canvas Width="300" Height="300" Background="DarkGray">
    <Button Click="Button_Click" x:Name="btnUpper">
        <Button.Template >
            <ControlTemplate TargetType="Button">
               
                    <Path Stroke="Black" Fill="Purple" StrokeThickness="4">
                        <Path.Data>
                            <PathGeometry>
                                <PathGeometry.Figures>
                                    <PathFigure x:Name="UpperArcFigure" StartPoint="0,100">
                                        <PathFigure.Segments>
                                            <ArcSegment     x:Name="UpperArcSegment"
                                                            IsLargeArc="True"
                                                            Size="20,20"
                                                            SweepDirection="Clockwise"                                            
                                                            Point="200,100" />
                                        </PathFigure.Segments>
                                    </PathFigure>
                                </PathGeometry.Figures>
                            </PathGeometry>
                        </Path.Data>
                    </Path>
                   
                
            </ControlTemplate>
        </Button.Template>
    </Button>
   
</Canvas>