我的 ArcSegment 未在 Xamarin.Ios 上实现

问题描述 投票:0回答:1
<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:无法定位程序集 'Xamarin.HotReload.Translations.resources'”,因此如果我想更改点,我需要重新加载应用程序,并且如果我启动在 UWP 而不是 Ios 上使用它时,我收到此错误:“忽略加载符号。该模块已优化,并且启用了‘仅我的代码’调试器选项。”但如果我取消单击“仅我的代码”,仍然没有任何更新。您有更新我的 ArcSegment 的想法吗?

c# xaml xamarin path xamarin.ios
1个回答
0
投票

是的,我可以重现。解决方法是删除它并重新添加。

这是一个例子。

假设 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);
}

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

希望有帮助!

© www.soinside.com 2019 - 2024. All rights reserved.