简体   繁体   English

如何在 UWP 中使区域内的路径可点击

[英]How to make PATH inside Region clickable in UWP

Hi I have a use case where I need to draw a complex shape(half-circle here just for demo) which I have done using PATH Uwp class now I need to make inside the region of PATH as clickable(ie user should able to click on the covered area of the shape drawn using PATH).嗨,我有一个用例,我需要绘制一个复杂的形状(这里是半圆只是为了演示),我使用 PATH Uwp class 现在我需要在 PATH 区域内制作为可点击的(即用户应该能够点击在使用 PATH 绘制的形状的覆盖区域上)。 Here is XAML anyone have an idea how to achieve then please share that will help a lot.这是 XAML 任何人都知道如何实现然后请分享这将有很大帮助。 Thanks谢谢

<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>

在此处输入图像描述

I am able to do this using wrapping content in button control anyone has a better approach then, please share.我可以使用在按钮控件中包装内容来做到这一点,那么任何人都有更好的方法,请分享。 This will make only Path Section clickable.Please make sure to set Path Fill Property to any color or Transparent这将使只有路径部分可点击。请确保将路径填充属性设置为任何颜色或透明

 <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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM