当前位置:网站首页>wpf path xaml写法和c#写法对比
wpf path xaml写法和c#写法对比
2022-08-09 11:09:00 【一头小驴】
转载自:https://www.c-sharpcorner.com/UploadFile/mahesh/path-in-wpf/
wpf path的c#写法,没有找到很多案例,对于很多需要代码去生成 路径点集合 的需求,可能还需要了解一下 path的c#写法。

xaml
<Window x:Class="_1_5GraphicsWpf.Window3"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:_1_5GraphicsWpf"
mc:Ignorable="d"
Title="Window3" Height="800" Width="1200">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Canvas x:Name="myCanvas" Grid.Column="0" Background="AliceBlue"></Canvas>
<Canvas Grid.Column="1">
<Path Stroke="Black" StrokeThickness="3" Fill="Blue">
<Path.Data>
<GeometryGroup>
<LineGeometry StartPoint="20,200" EndPoint="300,200" />
<EllipseGeometry Center="80,150" RadiusX="50" RadiusY="50" />
<RectangleGeometry Rect="80,167 150 30" />
</GeometryGroup>
</Path.Data>
</Path>
<Path Stroke="Black" StrokeThickness="3" Fill="Blue">
<Path.Data>
<EllipseGeometry Center="480,450" RadiusX="50" RadiusY="50" />
</Path.Data>
</Path>
</Canvas>
</Grid>
</Window>
xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace _1_5GraphicsWpf
{
/// <summary>
/// Window3.xaml 的交互逻辑
/// </summary>
public partial class Window3 : Window
{
System.Windows.Shapes.Path path;
public Window3()
{
InitializeComponent();
CreateAPath();
}
void Init()
{
Slider slider = new Slider();
}
///<summary>
/// Creates a blue path with black stroke
///</summary>
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;
myCanvas.Children.Add(bluePath);
}
}
}
边栏推荐
猜你喜欢
随机推荐
微信小程序——天气查询
enum in c language
fork creates multiple child processes
enum in c language
linux mysql操作的相关命令
性能测试(04)-表达式和业务关联-JDBC关联
Oracle数据库体系结构
使用.NET简单实现一个Redis的高性能克隆版(四、五)
prometheus接入mysqld_exporter
fork创建多个子进程
剖析STM32F103时钟系统
依赖注入(Dependency Injection)框架是如何实现的
sublime记录
bit、byte、KB、M、G、T相互关系
七夕?程序员不存在的~
Tensorflow realize parameter adjustment of linear equations
Looper 原理浅析
golang源代码阅读,sync系列-Cond
Oracle数据库的两种进入方式
电磁场与电磁波-场论基础









