////// Creates a line at run-time /// public void CreateALine() { // Create a Line Line redLine = new Line(); redLine.X1 = 50; redLine.Y1 = 50; redLine.X2 = 200; redLine.Y2 = 200; // Create a red Brush SolidColorBrush redBrush = new SolidColorBrush(); redBrush.Color = Colors.Red; // Set Line's width and color redLine.StrokeThickness = 4; redLine.Stroke = redBrush; // Add line to the Grid. LayoutRoot.Children.Add(redLine); }
Сворачивающаяся панель
в XAML файле в нужном гриде(Grid) добавим
<Grid.RenderTransform> <TranslateTransform X="0" /> </Grid.RenderTransform>
далее в коде
(gridDrawPanel.RenderTransform as TranslateTransform).X = 120;
PolyLine
SolidColorBrush yellowBrush = new SolidColorBrush(); yellowBrush.Color = Colors.Yellow; SolidColorBrush blackBrush = new SolidColorBrush(); blackBrush.Color = Colors.Black; // Create a polyline Polyline yellowPolyline = new Polyline(); yellowPolyline.Stroke = blackBrush; yellowPolyline.StrokeThickness = 4; // Create a collection of points for a polyline System.Windows.Point Point1 = new System.Windows.Point(10, 100); System.Windows.Point Point2 = new System.Windows.Point(100, 200); System.Windows.Point Point3 = new System.Windows.Point(200, 30); System.Windows.Point Point4 = new System.Windows.Point(250, 200); System.Windows.Point Point5 = new System.Windows.Point(200, 150); PointCollection polygonPoints = new PointCollection(); polygonPoints.Add(Point1); polygonPoints.Add(Point2); polygonPoints.Add(Point3); polygonPoints.Add(Point4); polygonPoints.Add(Point5); // Set Polyline.Points properties yellowPolyline.Points = polygonPoints; // Add polyline to the page cnvDrawPoly.Children.Add(yellowPolyline);
Ссылка
Path
////// Creates a blue path with black stroke /// public void CreateAPath() { // Create a blue and a black Brush SolidColorBrush blueBrush = new SolidColorBrush(); blueBrush.Color = Colors.Blue; SolidColorBrush blackBrush = new SolidColorBrush(); blackBrush.Color = Colors.Black; // Create a Path with black brush and blue fill Path bluePath = new Path(); bluePath.Stroke = blackBrush; bluePath.StrokeThickness = 3; bluePath.Fill = blueBrush; // Create a line geometry LineGeometry blackLineGeometry = new LineGeometry(); blackLineGeometry.StartPoint = new Point(20, 200); blackLineGeometry.EndPoint = new Point(300, 200); // Create an ellipse geometry EllipseGeometry blackEllipseGeometry = new EllipseGeometry(); blackEllipseGeometry.Center = new Point(80, 150); blackEllipseGeometry.RadiusX = 50; blackEllipseGeometry.RadiusY = 50; // Create a rectangle geometry RectangleGeometry blackRectGeometry = new RectangleGeometry(); Rect rct = new Rect(); rct.X = 80; rct.Y = 167; rct.Width = 150; rct.Height = 30; blackRectGeometry.Rect = rct; // Add all the geometries to a GeometryGroup. GeometryGroup blueGeometryGroup = new GeometryGroup(); blueGeometryGroup.Children.Add(blackLineGeometry); blueGeometryGroup.Children.Add(blackEllipseGeometry); blueGeometryGroup.Children.Add(blackRectGeometry); // Set Path.Data bluePath.Data = blueGeometryGroup; LayoutRoot.Children.Add(bluePath); }
Ссылка
Path.QuadraticBezierSegment
PathGeometry pg = new PathGeometry(); PathFigure pf = new PathFigure(); pf.StartPoint = new Point(10, 100); pf.IsFilled = false; QuadraticBezierSegment qbs = new QuadraticBezierSegment(); qbs.Point1 = new Point(120, 200); qbs.Point2 = new Point(300, 100); pf.Segments.Add(qbs); qbs = new QuadraticBezierSegment(); qbs.Point1 = new Point(320, 200); qbs.Point2 = new Point(300, 100); pf.Segments.Add(qbs); pg.Figures.Add(pf); GeometryGroup gg = new GeometryGroup(); gg.Children.Add(pg); System.Windows.Shapes.Path path = (System.Windows.Shapes.Path)cnvDrawPoly.Children[4]; path.Data = gg;
Комментариев нет:
Отправить комментарий