WPF C#路径:如何从路径数据串获得code几何体(而不是在XAML) [英] WPF C# Path: How to get from a string with Path Data to Geometry in Code (not in XAML)

查看:176
本文介绍了WPF C#路径:如何从路径数据串获得code几何体(而不是在XAML)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要生成在code一个WPF Path对象。

在XAML我可以做到这一点:

 <路径数据=M 100,200Ç100,25 400350 400175ħ280>

我怎样才能做到在code中的一样吗?

 路径path =新路径();
 Path.Data =富; //这不会接受一个字符串作为路径数据。

有一类/方法可用的字符串以PathData转换成的PathGeometry或类似的?

当然,不知何故XAML被解析和数据字符串转换?


解决方案

  VAR路径=新路径();
path.Data = Geometry.Parse(M 100,200Ç100,25 400350 400175ħ280);

Path.Data是几何类型。使用<击>反射 JustDecompile的(EFF红门)的,我看着它的TypeConverterAttribute几何定义(其中XAML串行器用来类型的值转换字符串几何)。这向我指出的GeometryConverter。检查出的实施,我看到它使用 Geometry.Parse 的路径的字符串值转换为一个几何实例。

I want to generate a WPF Path object in Code.

In XAML I can do this:

 <Path Data="M 100,200 C 100,25 400,350 400,175 H 280">

How can I do the same in Code?

 Path path = new Path();
 Path.Data = "foo"; //This won't accept a string as path data.

Is there a class/Method available that converts the string with PathData to PathGeometry or similar?

Surely somehow the XAML gets parsed and the Data-string converted?

解决方案

var path = new Path();
path.Data = Geometry.Parse("M 100,200 C 100,25 400,350 400,175 H 280");

Path.Data is of type Geometry. Using Reflector JustDecompile (eff Red Gate), I looked at the definition of Geometry for its TypeConverterAttribute (which the xaml serializer uses to convert values of type string to Geometry). This pointed me to the GeometryConverter. Checking out the implementation, I saw that it uses Geometry.Parse to convert the string value of the path to a Geometry instance.

这篇关于WPF C#路径:如何从路径数据串获得code几何体(而不是在XAML)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆