具有弯曲斜边的多边形三角形

时间:2015-06-02 11:47:18

标签: c# wpf xaml polygon

我可以用以下XAML创建一个多边形:

<Polygon Grid.Row="1"
         Grid.Column="1"
         Fill="{StaticResource GreenBrush}"
         Points="0,1 1,1 1,0"
         Stretch="Fill" />

这会形成一个直角斜边的直角三角形。但是我想要一个弯曲的斜边。这可能使用Polygon吗?如果不是我怎么能实现这个目标呢?

上面的XAML给出了左手三角形,但我想要对右手三角形有所帮助。

我觉得这可能很简单,但我似乎无法弄清楚

enter image description here

  • WPF
  • C#
  • Visual Studio 2012

2 个答案:

答案 0 :(得分:1)

也许这会对你有所帮助:)。

here

<强>更新

好的,所以这段代码:

<Canvas HorizontalAlignment="Left" Height="326" Margin="167,56,0,0" VerticalAlignment="Top" Width="311" MouseEnter="Canvas_MouseEnter" Background="#FFC7C5C5">
        <Path Stroke="Black" StrokeThickness="1">
            <Path.Data>
                <PathGeometry>
                    <PathGeometry.Figures>
                        <PathFigureCollection>
                            <PathFigure StartPoint="10,100">
                                <PathFigure.Segments>
                                    <PathSegmentCollection>
                                        <QuadraticBezierSegment Point1="200,150" Point2="300,100" />                                            
                                    </PathSegmentCollection>
                                </PathFigure.Segments>
                            </PathFigure>
                            <PathFigure StartPoint="10,100">
                                <PathFigure.Segments>
                                    <PathSegmentCollection>
                                        <LineSegment Point="10,300"></LineSegment>
                                    </PathSegmentCollection>
                                </PathFigure.Segments>
                            </PathFigure>
                            <PathFigure StartPoint="10,300">
                                <PathFigure.Segments>
                                    <PathSegmentCollection>
                                        <LineSegment Point="300,100"></LineSegment>
                                    </PathSegmentCollection>
                                </PathFigure.Segments>
                            </PathFigure>
                        </PathFigureCollection>
                    </PathGeometry.Figures>
                </PathGeometry>
            </Path.Data>
        </Path>
    </Canvas>

将使这个数字: here

答案 1 :(得分:1)

问题是因为Polygon只允许实现曲线效果的直线很难 你有两个选择 1)使用Blend创建路径
例如

<Path Data="M0.037120935,318.97711 L3.0000002,319 0,319 z M517,5.0000003 L517,319 3.0000002,319 C286.87436,319 517,178.4174 517,5.0000003 z M517,0 L517,5.0000003 516.89777,0.063097671 z" Fill="#FFFB0404" Stretch="Fill"/>

2)首先创建三角形并将其斜边与椭圆重叠。

<Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:ed="http://schemas.microsoft.com/expression/2010/drawing" x:Class="WpfApplication1.MainWindow"
        Title="MainWindow" Height="350" Width="525">
    <Grid x:Name="grid">
        <Polygon         
         Points="0,1 1,1 1,0"
         Stretch="Fill" Fill="#FF69FB04" />
        <Ellipse Fill="White" HorizontalAlignment="Left" Height="628" Margin="-511,-309,0,0" VerticalAlignment="Top" Width="1028"/>
        </Grid>

</Window>