C# 使用DataTemplate将WPF数据绑定到路径
我有这个C# 使用DataTemplate将WPF数据绑定到路径,c#,wpf,C#,Wpf,我有这个路径 <Path Stroke="Blue" StrokeThickness="2"> <Path.Data> <PathGeometry> <PathFigureCollection> <PathFigure StartPoint="20, 130"> <PathFigure.Segments> <LineSegment Po
路径
<Path Stroke="Blue" StrokeThickness="2">
<Path.Data>
<PathGeometry>
<PathFigureCollection>
<PathFigure StartPoint="20, 130">
<PathFigure.Segments>
<LineSegment Point="40, 4"/>
<LineSegment Point="60, 132"/>
</PathFigure.Segments>
</PathFigure>
</PathFigureCollection>
</PathGeometry>
</Path.Data>
有人告诉我,它可以用
在某些ItemSource
这看起来像是真的,因为坐标是
(SegmentWidth,y_1),(SegmentWidth*2,y_2),…,(SegmentWidth*n,y_n)
但是我不知道如何为这个路径制作DataTemplate
。我被告知应该在没有“代码隐藏”的情况下完成
如果使用多段线比使用路径更容易实现,它仍然很好。我唯一的目标是使用坐标将XML(第二个代码块)转换为类似于多段线的图形(SegmentWidth,Sample Val 1),…,(SegmentWidth*n,Sample Val n)
<Nums Color="Blue" Thick="2" SegmentWidth="20">
<Sample Val="130" />
<Sample Val="4" />
<Sample Val="132" />
</Nums>