当前位置:网站首页>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);
}
}
}
边栏推荐
- MATLAB代码实现三次样条插值
- pip common commands and changing source files
- PTA 换硬币
- ECCV 2022 Oral | CCPL: 一种通用的关联性保留损失函数实现通用风格迁移
- Missing URI template variable ‘employeeNumber‘ for method parameter of type String
- OC-NSTimer
- 微信小程序——天气查询
- Netscope: Online visualization tool for neural network structures
- CentOS6.5 32bit安装Oracle、ArcSde、Apache等配置说明
- faster-rcnn learn
猜你喜欢
CentOS6.5 32bit安装Oracle-11gR2步骤说明
剖析STM32F103时钟系统
Antdv+Asp.net WebApi开发学生信息管理系统(一)
x86 Exception Handling and Interrupt Mechanism (1) Overview of the source and handling of interrupts
MATLAB代码实现三次样条插值
centos7.5 设置Mysql开机自启动
双向链表的各种操作
性能测试(05)-表达式和业务关联-json关联
ICML 2022 | Out-of-Distribution Detection with Deep Nearest Neighbors
MDK添加注释模板
随机推荐
Qt获取EXE可执行文件的上一级目录下的文件
caffe ---make all editing error
微信小程序——天气查询
Quartz的理解
Invisible OOM in kubernetes
The torch. The stack () official explanation, explanation and example
Open3D 点云平均点间距评估
OC-块对象
matlab fcnchk 函数用法
People | How did I grow quickly from programmer to architect?
PoseNet: A Convolutional Network for Real-Time 6-DOF Camera Relocalization Paper Reading
剖析STM32F103时钟系统
1009 Product of Polynomials C语言多项式乘积(25分)
Arduino学习总结 + 实习项目
golang interface “坑记录“
Preparation for gold three silver four: how to successfully get an Ali offer (experience + interview questions + how to prepare)
TensorFlow: NameError: name 'input_data' is not defined
faster-rcnn learn
【C language】动态数组的创建和使用
STM32启动方式及BootLoader