0

如何更改 C# 代码中的位置元素(行)?

<Grid x:Name="SetShipsGrid">
        <Path Name="Line" Stroke="red" StrokeThickness="1" >
            <Path.Data >
                <GeometryGroup>
                    <LineGeometry StartPoint="50,50" EndPoint="350,50"></LineGeometry>
                </GeometryGroup>
            </Path.Data>
        </Path>
</Grid>
4

2 回答 2

0

在将名称添加到行后面的代码中:

<Grid x:Name="SetShipsGrid">
    <Path Name="Line" Stroke="red" StrokeThickness="1" >
        <Path.Data >
            <GeometryGroup>
                <LineGeometry x:Name="line" StartPoint="50,50" EndPoint="350,50"></LineGeometry>
            </GeometryGroup>
        </Path.Data>
    </Path>
</Grid>

然后在 xaml.cs 中:

this.line.StartPoint = ....
于 2013-06-10T09:56:19.680 回答
0

您可以将起点和终点绑定到公共属性

xml:

    <Grid x:Name="SetShipsGrid">
        <Path Name="Line" Stroke="red" StrokeThickness="1" >
            <Path.Data >
                <GeometryGroup>
                    <LineGeometry StartPoint="{Binding StartPoint}" EndPoint="{Binding EndPoint}" />
                </GeometryGroup>
            </Path.Data>
        </Path>
    </Grid>

代码:

    private Point _startPoint = new Point(5, 5);
    private Point _endPoint = new Point(100, 100);

    public Point StartPoint
    {
        get { return _startPoint; }
        set { _startPoint = value; NotifyPropertyChanged(); }
    }

    public Point EndPoint
    {
        get { return _endPoint; }
        set { _endPoint = value; NotifyPropertyChanged(); }
    }
于 2013-06-10T22:36:42.800 回答