动态设置path.data for system.windows.shapes.path



我正在编写以下代码,以使用system.windows.shapes.path创建图表。现在,我将其设置为XAML代码中的路径:

<Grid FlowDirection="LeftToRight">
    <Canvas  HorizontalAlignment="Center" Name="PitchCanvas" VerticalAlignment="Center" Margin="30,0,370,470">
        <Canvas.RenderTransform>
            <ScaleTransform ScaleX="{Binding ElementName=SignalScaleSlider, Path=Value}" />
        </Canvas.RenderTransform>
        <Path Data="M 10,450 L 10,10 M 26,450 L 26,10 M 42,450 L 42,10 M 58,450 L 58,10 M 74,450 L 74,10 M 90,450 L 
              90,10 M 106,450 L 106,10 M 122,450 L 122,10  M 138,450 L 138,10 M 154,450 L 154,10 M 170,450 L 170,10
                  M 202,450 L 202,10 M 234,450 L 234,10 M 266,450 L 266,10 M 350,450 L 350,10
                  M 10,350 L 350,350 M 10,330 L 350,330 M 10,310 L 350,310 M 10,290 L 350,290 M 10,270 L 350,270 M 10,250 L 350,250
                  M 10,230 L 350,230 M 10,210 L 350,210 M 10,190 L 350,190 M 10,170 L 350,170 M 10,150 L 350,150 M 10,130 L 350,130 
                  M 10,110 L 350,110 M 10,90 L 350,90 M 10,70 L 350,70 M 10,50 L 350,50 M 10,30 L 350,30 M 10,10 L 350,10
                  " Height="454" Name="RangeSignalPath1" Stroke="Silver" StrokeThickness="0.5" />
        <Path Data=" M 10,450 L 350,450  M 10,330 L 350,330 M 10,230 L 350,230 M 10,130 L 350,130 M 10,30 L 350,30"
                  Name="RangeSignalPath2" Stroke="Silver" StrokeThickness="1" Height="387" />

有什么方法可以动态地编写它的路径'data(在C#代码中)而不是XAML代码?

正如您所看到的那样

根据需要创建字符串。使用 Geometry.Parse(),它返回一个您分配给RangeSignalPath1.DataGeometry对象:

Geometry g = Geometry.Parse(<your string>);
RangeSignalPath1.Data = g;

相关内容

  • 没有找到相关文章

最新更新