【问题标题】:How to draw a spring in C# wpf using xaml如何使用 xaml 在 C# wpf 中绘制弹簧
【发布时间】:2014-05-26 21:44:44
【问题描述】:

我如何从 xaml 代码中创建弹簧..我正在考虑使用贝塞尔线段...但我不知道如何...

         ` <Path Stroke="Black" StrokeThickness="1" Canvas.Left="244.77" Canvas.Top="45.655" RenderTransformOrigin="0.5,0.5" Height="31.6" Stretch="Fill" Width="25.658">
            <Path.RenderTransform>
                <TransformGroup>
                    <ScaleTransform/>
                    <SkewTransform/>
                    <RotateTransform Angle="-89.333"/>
                    <TranslateTransform/>
                </TransformGroup>
            </Path.RenderTransform>
            <Path.Data>
                <PathGeometry>
                    <PathGeometry.Figures>
                        <PathFigureCollection>
                            <PathFigure StartPoint="10,100">
                                <PathFigure.Segments>
                                    <PathSegmentCollection>
                                        <BezierSegment Point1="100,0" Point2="200,200" Point3="300,100" />
                                    </PathSegmentCollection>
                                </PathFigure.Segments>
                            </PathFigure>
                        </PathFigureCollection>
                    </PathGeometry.Figures>
                </PathGeometry>
            </Path.Data>
        </Path>
        <Path Stroke="Black" StrokeThickness="1" Canvas.Left="244.77" Canvas.Top="45.655" RenderTransformOrigin="0.5,0.5" Height="31.6" Stretch="Fill" Width="25.658">
            <Path.RenderTransform>
                <TransformGroup>
                    <ScaleTransform/>
                    <SkewTransform/>
                    <RotateTransform Angle="-89.333"/>
                    <TranslateTransform/>
                </TransformGroup>
            </Path.RenderTransform>
            <Path.Data>
                <PathGeometry>
                    <PathGeometry.Figures>
                        <PathFigureCollection>
                            <PathFigure StartPoint="10,100">
                                <PathFigure.Segments>
                                    <PathSegmentCollection>
                                        <BezierSegment Point1="100,0" Point2="200,200" Point3="300,100" />
                                    </PathSegmentCollection>
                                </PathFigure.Segments>
                            </PathFigure>
                        </PathFigureCollection>
                    </PathGeometry.Figures>
                </PathGeometry>
            </Path.Data>
        </Path>`

那是两个,但我想要一个包含五个这样的小家伙......也许看起来更自然......

【问题讨论】:

  • 如果你从远处看你的xaml,它看起来就像一个春天! =D 严肃地说,您是否先尝试过搜索? Click, click...
  • 我看到了……但问题是我不想要一个 c# 编码的弹簧……我想要它在 xaml 中……我知道它看起来像一个弹簧,但有 2 个那里的贝塞尔线段,我只想要一个有 5 个小贝塞尔线段
  • 尝试在Blend中绘制,或许有一些工具可以优化?

标签: c# wpf xaml


【解决方案1】:

我建议你找一张拼贴得很好的图片。然后您可以画一条线并使用 VisualBrush 将图像作为 ImageSource。这应该很好用:

How to set a .PNG image as a TILED background image for my WPF Form?

添加了一个示例:

<Grid>
    <Rectangle HorizontalAlignment="Left" Height="272" Margin="70,54,0,0" StrokeThickness="1" VerticalAlignment="Top" Width="12.166">
        <Rectangle.Fill>
            <ImageBrush
                Viewport="0,0,1,0.1"
                TileMode="FlipY"
                AlignmentX="Left"
                AlignmentY="Top"
                ImageSource="helix.png" Stretch="Uniform" />
        </Rectangle.Fill>
    </Rectangle>            
</Grid>

看起来像这样:

使用此 png 时:

我相信您会找到更好的平铺图像... ;)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-15
    • 1970-01-01
    • 2023-04-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多