当前位置:网站首页>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);
}
}
}
边栏推荐
- linux mysql操作的相关命令
- PoseNet: A Convolutional Network for Real-Time 6-DOF Camera Relocalization Paper Reading
- Preparation for gold three silver four: how to successfully get an Ali offer (experience + interview questions + how to prepare)
- x86 exception handling and interrupt mechanism (2) interrupt vector table
- x86异常处理与中断机制(1)概述中断的来源和处理方式
- Numpy常用操作博客合集
- PTA 换硬币
- golang 三种指针类型具体类型的指针、unsafe.Pointer、uintptr作用
- People | How did I grow quickly from programmer to architect?
- UNIX哲学
猜你喜欢
随机推荐
matlab图像分割,从基因芯片荧光图像中提取阴性点(弱)和阳性点(强)
ICML 2022 | Out-of-Distribution检测与深最近的邻居
Input and output of cnn
PTA习题 分类统计字符个数(C)
Qt 国际化翻译
Oracle数据库的两种进入方式
Open3D 点云平均点间距评估
STM32启动方式及BootLoader
ThreadLocal及其内存泄露分析
OC-块对象
The use of C language typedef 】 : structure, basic data types, and array
MySQL传统方案和通过SSH连接哪个好?
Oracle数据库体系结构
【精华文】C语言结构体特殊情况分析:结构体指针 / 基本数据类型指针,指向其他结构体
无刷无霍尔BLCD电机控制
Number theory knowledge
faster-rcnn learn
【Subpixel Dense Refinement Network for Skeletonization】CVPR2020论文解读
vite的原理,手写vite
gdb 10.2的安装