我有一个Xamarin表单应用程序,它有一个每秒运行一次的事件并从 Characteristic 获取数据 . 在这种情况下,我创建整个布局,设置数据并更新视图,如下所示:

public void UpdateDisplay (ICharacteristic c) {
   //Lots of irrelevant code above this.
   foreach (Accelerometer item in acceloReadings)
   {
     counter += 1;
     //Y-graph data
     DataPoint itemPointY = new DataPoint();
     itemPointY.X = counter;
     itemPointY.Y = item.yAxes;
     PointsY.Add(itemPointY);
   }

 yAs = new PlotModel("Variations Y-Axis");
 yAs.PlotType = PlotType.XY;
 yAs.Axes.Add(new LinearAxis(AxisPosition.Left, -270, 270));

 y = new LineSeries();
 //Custom color
 y.Color = OxyColor.FromArgb(255, 154, 200, 253);
 y.ItemsSource = PointsY;
 yAs.Series.Add(y);

 opvY = new OxyPlotView
 {
     WidthRequest = 100,
     HeightRequest = 100,
     BackgroundColor = Color.Aqua
  };
  opvY.Model = yAs;

  Content = new StackLayout
  {
    opvY,
  }
  };
 }

该代码填满了所有模型等,然后我想用同样的方法更新我的图形 . 我尝试了几种方法:

//After all the data is re-loaded and added I want to refresh my graphs.
   xAs.InvalidatePlot(true);
   opvX.Model.InvalidatePlot(true);
   opvX.InvalidateDisplay();

然而,这些都没有任何成功 . 当你看the official docs时,你可以清楚地看到它的状态:

"To update the plot, you must do one of the following alternatives:

Change the Model property of the PlotView control
Call Invalidate on the PlotView control
Call Invalidate on the PlotModel"

虽然我尝试了所有这些方法,但没有一个更新我的图表/视图 . 当我手动点击并调整图表大小时,我可以看到数据已刷新 . 最后,我想在main方法中创建一次图形,然后使用 InvalidateDisplay 更新图形 . 那么,我做错了什么?!