XAML 我的ArcSegment无法在Xamarin.Ios上实现

kxe2p93d  于 12个月前  发布在  iOS
关注(0)|答案(1)|浏览(110)
<Path x:Name="PathCircle" Stroke="Black" StrokeThickness="17" StrokeLineJoin="Round" TranslationX="125" TranslationY="530">
                    <Path.Data >
                        <PathGeometry>
                            <PathFigure StartPoint="0, 0" >
                                <ArcSegment  x:Name="CircleClim" Size="80, 80"
                                Point="32, -64" 
                                IsLargeArc="False" 
                                SweepDirection="Clockwise" />
                            </PathFigure>
                        </PathGeometry>
                    </Path.Data>
                </Path>

这是我的问题,我不能更新一个arcSegment,我已经创建了一个arcSegment,在温度的函数中,我需要改变点。我可以在第一次加载应用程序时显示它,但当我更改点时没有任何变化,它在屏幕上没有变化,但使用Console.WriteLine我可以看到我的点发生了变化。

private void SwitchCircleClim()
    {
        double radius = 80;
        double angle = (10-temp)*9*Math.PI/180;

        double x = 80 +(radius * Math.Cos(angle));
        double y = (radius * Math.Sin(angle));
        CircleClim.Point=new Point(x, y);   
        Console.WriteLine(CircleClim.Point.X);
        Console.WriteLine(CircleClim.Point.Y);

    }

未在此ArcSegment上启用热重载:“Xamarin.iOS:Unable to locate assembly 'Xamarin.HotReload.Translations.resources'",所以如果我想改变点,我需要重新加载应用程序,如果我在UWP而不是iOS上启动它,我会得到这个错误:“忽略加载符号。模块被优化并且'仅我的代码'调试器选项被启用。”但是如果我取消单击'仅我的代码'仍然没有更新。您有更新ArcSegment的想法吗?

rqmkfv5c

rqmkfv5c1#

是的,我可以复制。解决方法是删除它,然后再次在代码后面添加它。
这里有一个例子。
假设Path在StackLayout中:

<StackLayout x:Name="mystack" WidthRequest="300" HeightRequest="300">
    <Path x:Name="PathCircle1" Stroke="Black" StrokeThickness="17" 
    ......the same as your code here
   
    </Path>
</StackLayout>

在代码后面,

private void SwitchCircleClim()
{
    // first remove it
    mystack.Children.Remove(PathCircle1);

    // create a new one
    PathSegmentCollection pathSegments = new PathSegmentCollection();
    ArcSegment arcSegment = new ArcSegment()
    {
        Size = new Size(80, 80),
        Point = new Point(50, 50),
        IsLargeArc = false,
        SweepDirection = SweepDirection.Clockwise

    };
    pathSegments.Add(arcSegment);
    PathFigure pathFigure = new PathFigure();
    pathFigure.Segments = pathSegments;
    PathFigureCollection pathFigures = new PathFigureCollection();
    pathFigures.Add(pathFigure);

    Path PathCircle = new Path()
    {
        Stroke = new SolidColorBrush(Color.Black),
        StrokeThickness = 17,
        StrokeLineJoin = PenLineJoin.Round,
        TranslationX = 0,
        TranslationY = 0
    };

    PathCircle.Data = new PathGeometry()
    {
        Figures = pathFigures,
    };
    

    // then add it again
    mystack.Children.Add(PathCircle);
}

注意:由于此方法在后面的代码中绘制arcsegment,这意味着您可以重用这部分代码来初始化或修改圆弧,而不必使用xaml部分再次绘制圆弧。这将使代码更加简洁。

希望能帮上忙!

相关问题