首页 > 其他分享 >WPF StreamGeometry

WPF StreamGeometry

时间:2023-01-16 01:33:35浏览次数:61  
标签:LineTo join Point ctx StreamGeometry new WPF true

使用路径标记语法 StreamGeometry 来设计最大化 最小化 恢复和关闭按钮,以下为恢复按钮的路径,和拿邮件系统按钮做了对比,完全吻合

前一张图片设置了不透明度为40
后一张为邮件恢复按钮

先看下代码效果图

  <Grid Background="#FFF0F0F0">
        <ContentControl x:Name="Content" />
   </Grid>
        public MainWindow()
        {
            InitializeComponent();

            var myPath = new Path();
            myPath.Stroke = Brushes.Black;
            myPath.StrokeThickness = 1;

            // Create a StreamGeometry to use to specify myPath.
            StreamGeometry geometry = new StreamGeometry();
            geometry.FillRule = FillRule.EvenOdd;

            // Open a StreamGeometryContext that can be used to describe this StreamGeometry 
            // object's contents.
            using (StreamGeometryContext ctx = geometry.Open())
            {

                // Begin the triangle at the point specified. Notice that the shape is set to 
                // be closed so only two lines need to be specified below to make the triangle.
                ctx.BeginFigure(new Point(30, 50), true /* is filled */, true /* is closed */);

                // Draw a line to the next specified point.
                ctx.LineTo(new Point(30, 60), true /* is stroked */, false /* is smooth join */);

                // Draw another line to the next specified point.
                ctx.LineTo(new Point(110, 60), true /* is stroked */, false /* is smooth join */);
                ctx.LineTo(new Point(110, 50), true /* is stroked */, false /* is smooth join */);
                // Begin the triangle at the point specified. Notice that the shape is set to 
                // be closed so only two lines need to be specified below to make the triangle.
                ctx.BeginFigure(new Point(30, 120), true /* is filled */, true /* is closed */);

                // Draw a line to the next specified point.
                ctx.LineTo(new Point(30, 130), true /* is stroked */, false /* is smooth join */);

                // Draw another line to the next specified point.
                ctx.LineTo(new Point(110, 130), true /* is stroked */, false /* is smooth join */);
                ctx.LineTo(new Point(110, 120), true /* is stroked */, false /* is smooth join */);

                ctx.BeginFigure(new Point(30, 60), true /* is filled */, true /* is closed */);

                // Draw a line to the next specified point.
                ctx.LineTo(new Point(30, 120), true /* is stroked */, false /* is smooth join */);

                // Draw another line to the next specified point.
                ctx.LineTo(new Point(40, 120), true /* is stroked */, false /* is smooth join */);
                ctx.LineTo(new Point(40, 60), true /* is stroked */, false /* is smooth join */);
                // Begin the triangle at the point specified. Notice that the shape is set to 
                // be closed so only two lines need to be specified below to make the triangle.
                ctx.BeginFigure(new Point(100, 60), true /* is filled */, true /* is closed */);

                // Draw a line to the next specified point.
                ctx.LineTo(new Point(100, 120), true /* is stroked */, false /* is smooth join */);

                // Draw another line to the next specified point.
                ctx.LineTo(new Point(110, 120), true /* is stroked */, false /* is smooth join */);
                ctx.LineTo(new Point(110, 60), true /* is stroked */, false /* is smooth join */);

                ctx.BeginFigure(new Point(50, 50), true /* is filled */, true /* is closed */);

                // Draw a line to the next specified point.
                ctx.LineTo(new Point(50, 30), true /* is stroked */, false /* is smooth join */);

                // Draw another line to the next specified point.
                ctx.LineTo(new Point(130, 30), true /* is stroked */, false /* is smooth join */);
                ctx.LineTo(new Point(130, 110), true /* is stroked */, false /* is smooth join */);
                ctx.LineTo(new Point(110, 110), true /* is stroked */, false /* is smooth join */);
                ctx.LineTo(new Point(110, 100), true /* is stroked */, false /* is smooth join */);
                ctx.LineTo(new Point(120, 100), true /* is stroked */, false /* is smooth join */);
                ctx.LineTo(new Point(120, 40), true /* is stroked */, false /* is smooth join */);
                ctx.LineTo(new Point(60, 40), true /* is stroked */, false /* is smooth join */);
                ctx.LineTo(new Point(60, 50), true /* is stroked */, false /* is smooth join */);

            }

            // Freeze the geometry (make it unmodifiable)
            // for additional performance benefits.
            geometry.Freeze();

            // Specify the shape (triangle) of the Path using the StreamGeometry.
            myPath.Data = geometry;

            // Add path shape to the UI.
            this.Content.Content = myPath;
            System.Diagnostics.Debug.WriteLine(geometry);

https://learn.microsoft.com/zh-cn/dotnet/desktop/wpf/graphics-multimedia/how-to-create-a-shape-using-a-streamgeometry?view=netframeworkdesktop-4.8
https://vimsky.com/examples/detail/csharp-ex-System.Windows.Media-StreamGeometry---class.html
https://learn.microsoft.com/zh-cn/dotnet/desktop/wpf/graphics-multimedia/path-markup-syntax?view=netframeworkdesktop-4.8

标签:LineTo,join,Point,ctx,StreamGeometry,new,WPF,true
From: https://www.cnblogs.com/androllen/p/17054561.html

相关文章