这显示了如何从代码中做到这一点。我不确定这是否能解决你的问题 - 你说“混合?” 在标题中,我不知道在 Blend 中执行此操作的方法。但我希望这可能会有所帮助。
第一步是将 转换EllipseGeometry
为 a PathGeometry
:
var geom = new EllipseGeometry(new Point(5, 4), 4, 4);
var pathGeometry = PathGeometry.CreateFromGeometry(geom);
一旦你有一个PathGeometry
你可以简单地打电话ToString
,它会给你字符串表示:
string pathText = pathGeometry.ToString();
在我的系统上,这会产生以下相当冗长的文本:
“M9,4C9,6.20913899932317 7.209389323,885,8.209999323,885,8.20919993,05,87.20919993,05,87.20938993,05,8,8.2091989323,878,87.209389837688,8,8.2091389932317067839323170678393768,87.209.0683837.>>>>>>>>>>>>>
现在,如果您想最终得到将字符串输入 Xaml 时会得到的结果,则需要多一步,因为 Xaml 是您提供的表单:
<Path Data="M 0 5 L 3 10 10 0"/>
doesn't produce a PathGeometry
. It produces a StreamGeometry
, which is a slightly more efficient, but fixed representation of the path. (The main difference being that you can't get hold of individual objects representing the various figures and segements in a StreamGeometry
, whereas you can with a PathGeometry
. StreamGeometry
is cheaper, as a result.)
You can get a StreamGeometry
from the path text:
var streamGeometry = StreamGeometry.Parse(pathText);
And then if you want that in a Path
just build it:
var p = new Path { Data = streamGeometry };
Depending on what your exact goal is, there may be more efficient ways to do this. (StreamGeometry
is a more efficient representation because it ends up creating far fewer objects. But the route by which my code gets to that representation is not very efficient, so you might be better off just stopping with the PathGeometry
that the very first code snippet produces. Alternatively, if your goal is really just to get the path text, then the PathGeometry
is also sufficient for your needs.)