【问题标题】:How to make PATH inside Region clickable in UWP如何在 UWP 中使区域内的 PATH 可点击
【发布时间】:2020-12-10 23:46:03
【问题描述】:

嗨,我有一个用例,我需要绘制一个复杂的形状(这里是半圆,只是为了演示)我已经使用 PATH Uwp 类完成了现在我需要在 PATH 的区域内制作为可点击的(即用户应该能够单击使用 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>

【问题讨论】:

    标签: c# xaml uwp uwp-xaml


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-09
      • 1970-01-01
      • 1970-01-01
      • 2011-08-29
      • 2011-08-28
      • 2014-10-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多