这与我之前提到的有关Cubic Bezier的问题类似.我有一个起点,一个终点,以及一个位于Quadratic Bezier的点.鉴于这三点,我希望能够在WPF中绘制QuadraticBezierSegment,但我需要单个ControlPoint值(在QuadraticBezierSegment中它是Point1)才能绘制它.
是否有计算或手段可以确定该值并因此绘制我的QuadraticBezier?
谢谢!
我想要由LineSegment组成的PathGeometry.
所以,我使用第一个代码,但它是错误的.
PathGeometry temp = (PathGeometry)Geometry.Parse(
"<PathGeometry.Figures>" +
"<PathFigure StartPoint=\"193.5,283.5\" IsClosed=\"True\">" +
"<PathFigure.Segments>" +
"<LineSegment Point=\"418.5,283.5\" />" +
"<LineSegment Point=\"418.5,508.5\" />" +
"<LineSegment Point=\"193.5,508.5\" />" +
"<LineSegment Point=\"193.5,283.5\" />" +
"</PathFigure.Segments>" +
"</PathFigure>" +
"</PathGeometry.Figures>");
Run Code Online (Sandbox Code Playgroud)
如果我使用第二个代码,它不是错误,但它不包含LineSegment.结果将是PolyLineSegment,但我想要LineSegment.
PathGeometry temp = (PathGeometry)Geometry.Parse(
"M29,329L30,331L31,334L33,336L34,338L36,341L38,343L39,345L41,348L44,352L46,353L47,355L48,356L49,357L49,357L50,358L50,358L51,357L50,356L51,354L51,350L53,342L54,334L58,320L60,315L61,311L63,308L63,306L64,304L65,303L65,302L66,301L66,301L66,301L66,301L66,301L66,301L66,301");
Run Code Online (Sandbox Code Playgroud)
如何将XAML PathGeometry转换为WPF PathGeometry?
谢谢
我想创建一个ResourceDictionary一拉这个答案包含StreamGeometries已Transforms设置:
<ResourceDictionary>
<StreamGeometry x:Name="Chevrons">
<StreamGeometry.Transform>
<TranslateTransform X="20" Y="120"/>
</StreamGeometry.Transform>
M21.750001,94.749999 L34.000002,117.66218 30.625003,133.62501 17 [...]
</StreamGeometry>
</ResourceDictionary>
Run Code Online (Sandbox Code Playgroud)
但是,我收到以下错误:
1:无法向"StreamGeometry"类型的对象添加内容.
和
2:处理初始化字符串' {PathData} '时遇到TypeConverter语法错误.通过TypeConverter创建的对象不允许使用元素属性.
所以我试了一下PathGeometry并得到了这个错误:
无法将指定的值分配给集合.预期以下类型:"PathFigure".
有没有办法在XAML代码中将变换应用于几何?或者我只需要通过代码来完成它?
我在我的Xaml文件中定义了一个资源,如下所示:
<Path x:Key="myPath"
Data="M14.773241,18.080208 C12.373256,18.080208 10.239936,19.30687 10.239936,27.573483
L10.239936,36.106766 C10.239936,45.440037 12.586588,46.506699 14.986573,46.506699
C18.613216,46.506699 19.359879,42.400059 19.359879,35.3601 L19.359879,27.733482
C19.359879,20.05353 17.386559,18.080208 14.773241,18.080208 z M14.879907,11.786915
C17.973221,11.786915 22.293194,13.013573 24.906511,17.920212 C26.773167,21.386856
27.519829,27.093487 27.519829,32.213455 C27.519829,34.506775 27.306496,41.706726
24.906511,46.453365 C23.626518,49.013351 20.906536,52.799992 15.199905,52.799992
C2.1333201,52.799992 2.1333201,37.600086 2.1333201,32.160122 C2.1333201,28.05348
2.1333201,22.666847 4.4266391,18.453541 C5.8666301,15.840225 8.639946,11.786915
14.879907,11.786915 z"
/>
Run Code Online (Sandbox Code Playgroud)
我希望能够将此路径的多个"实例"(以及其他几个)添加到StackPanel.当然,我不能简单地将"myPath"添加到面板中,因为它已经是另一个容器的子节点.
但是,我似乎无法克隆路径.我试过了:
Path clone = new Path()
{
Data = source.Data
};
Run Code Online (Sandbox Code Playgroud)
但没有运气......价值超出预期范围的例外.
最后,我尝试挖掘source.Data(一个PathGeometry),但它不包含PathFigures ...我不知道为什么,因为如果我将它从资源部分直接复制到面板,则Path会渲染.
是什么赋予了?
谢谢,塞尔吉奥
在我完成2D三角测量后,一些三角形具有相同的颜色,我想重新组合它们以绘制成相似颜色的图形路径.我发现如果我只是逐个绘制三角形,一些图形渲染器会显示三角形之间的接缝(至少如果涉及抗锯齿和/或透明度).
那么我如何获取一组(非重叠)三角形并生成一个图形路径,其中可能包含孔和不相交的多边形?
盲目地将三角形添加到图形路径实际上非常适合填充(当然不是用于抚摸),但是导出那些额外的内部点感觉不对.
geometry triangulation pathgeometry computational-geometry graphicspath
我有很多PathGeometry实例,可以为不同的按钮绘制各种图形.所以我创建了一个按钮类型来显示Path,然后根据按钮状态更新Path.Stroke.所以在禁用时显示为灰色,鼠标结束时显示不同的颜色.标准的东西......
<Style x:Key="BasePathButton" TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border Name="Border"
<Path x:Name="Path" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter TargetName="Path" Property="Stroke" Value="Gray"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="Path" Property="Stroke" Value="Green"/>
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter TargetName="Path" Property="Stroke" Value="Red"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Run Code Online (Sandbox Code Playgroud)
但显然我需要为每个按钮实例使用不同的Path.Data.所以我创建了一个用于设置Path.Data的BasedOn样式,就像这样......
<Style x:Key="NLB" TargetType="{x:Type Button}" BasedOn="{StaticResource BasePathButton}">
<Setter TargetName="Path" Property="Data" Value="{StaticResource LeftPathGeometry}"/>
</Style>
Run Code Online (Sandbox Code Playgroud)
...但是失败了,发现无法找到TargetName ="Path"的错误.任何想法如何解决这一问题?或者也许是一种更好的方法来创建一个具有Path的按钮,该Path使用要使用的几何参数化?
我需要用不同颜色,厚度等的线条绘制相同的图纸.
我可以创建两个PathGeometry实例,但我不能在它们上设置颜色.
我可以创建两个Path实例,但无法在控件中显示它们.
我究竟做错了什么?
谢谢你的评论!
丹麦安德斯.
下面的代码只在我的控件中显示"集合",但我认为这可能是答案的起点......
var pathFigure1 = new PathFigure(new Point(0, 0),
new List<PathSegment> {new LineSegment(new Point(10, 10), true)}, false);
var pathFigure2 = new PathFigure(new Point(20, 20),
new List<PathSegment> {new LineSegment(new Point(30, 30), true)}, false);
var g1 = new PathGeometry(new List<PathFigure> {pathFigure1});
var g2 = new PathGeometry(new List<PathFigure> {pathFigure2});
var p1 = new System.Windows.Shapes.Path
{
Data = g1,
Stroke = new SolidColorBrush(Color.FromRgb(0, 0, 0))
};
var p2 = new System.Windows.Shapes.Path
{
Data = g2,
Stroke = new SolidColorBrush(Color.FromRgb(170, …Run Code Online (Sandbox Code Playgroud) 我有一个椭圆几何.我想用C#从中心到圆的边缘绘制一条线来显示椭圆的半径.我怎样才能做到这一点?
注意:椭圆的中心和半径不固定,由用户定义.

我想知道是否有任何方法可以在xaml中使用元素中的PathFigure资源PathGeometry.假设我有一个ResourceDictionary,其中有两个PathFigure对象,'x:Key'属性分别等于"Figure1"和"Figure2".我的目标是创建一个PathGeometry带有Figures包含图1和图2的集合的属性.我可以使用代码隐藏文件轻松地完成它,但是我想知道有没有办法只使用xaml.
<PathFigure IsClosed="True" StartPoint="2,9" x:Key="Figure1">
<ArcSegment Point="15,9" Size="6.5, 2"/>
<LineSegment Point="15,12"/>
<ArcSegment Point="2,12" Size="6.5, 2"/>
</PathFigure>
<PathFigure IsClosed="True" StartPoint="10,7" x:Key="Figure2">
<LineSegment Point="10, 2"/>
<LineSegment Point="13,2"/>
<LineSegment Point="13,7"/>
<ArcSegment Point="10,7" Size="2,2" IsLargeArc="True"/>
</PathFigure>
Run Code Online (Sandbox Code Playgroud)
我现在可以创建一个PathGeometry:
<PathGeometry FillRule="Nonzero" x:Key="1">
<PathFigureCollection>
//Here I want to put Figure1 and Figure2
</PathFigureCollection>
</PathGeometry>
Run Code Online (Sandbox Code Playgroud)
我想我可以写一些MarkupExtension来做以下事情,但我正在寻找最好的方法.谢谢你的建议.
pathgeometry ×9
wpf ×7
c# ×4
xaml ×3
path ×2
bezier ×1
button ×1
cloning ×1
ellipse ×1
geometry ×1
graphicspath ×1
resources ×1
silverlight ×1
styles ×1