1
OxyPlot
で問題が発生しています。グラフにデータをロードすると、それは完全にうまくいきますが、詳細アクティビティに移動してメインアクティビティに戻ると、まだグラフが表示されますが、プロットデータはありません。ただ空です。OxyPlot navigation
メインアクティビティに戻ると、PlotView
はnullになりますが、Lineseries
はまだデータを保持しています。
のViewModel
簡単にするために、私はちょうどプロット点(グラフの形状)の同じグループが数回繰り返さ含まれている簡単なObservableCollection
を作成しました。
public class MyViewModel : BaseViewModel
{
PlotModel GeneratePlotPoints()
{
var mo = new PlotModel();
var s1 = new LineSeries()
{
Color = OxyColors.SkyBlue,
MarkerType = MarkerType.Circle,
MarkerSize = 6,
MarkerStroke = OxyColors.White,
MarkerFill = OxyColors.SkyBlue,
MarkerStrokeThickness = 1.5
};
s1.Points.Add(new DataPoint(0, 10));
s1.Points.Add(new DataPoint(10, 40));
s1.Points.Add(new DataPoint(40, 20));
s1.Points.Add(new DataPoint(60, 30));
mo.Series.Add(s1);
return mo;
}
List<PlotModel> GenerateGraph()
{
var graphPlots = new List<PlotModel>();
int counter = 0;
while (counter < 10)
{
graphPlots.Add(GeneratePlotPoints());
counter++;
}
return graphPlots;
}
public List<PlotModel> GraphPlots => GenerateGraph();
}
レイアウト
RecyclerViewとあなたの主なレイアウト。
<MvxRecyclerView
android:id="@+id/myRecyclerView"
android:layout_marginTop="10dp"
android:scrollbars="vertical"
android:divider="@null"
android:layout_width="match_parent"
android:layout_height="match_parent"
local:MvxBind="ItemsSource GraphPlots"
local:MvxItemTemplate="@layout/mycardview" />
mycardview
レイアウトテンプレート。ポイントの使用が(この場合はPlotModel)モデル全体にバインドするMVXを伝えるために使用されていることに注意してください
<?xml version="1.0" encoding="utf-8" ?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<oxyplot.xamarin.android.PlotView
android:id="@+id/Plot"
android:layout_width="match_parent"
android:layout_height="match_parent"
local:MvxBind="Model ."/>
</RelativeLayout>
ビュー
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
var ignored = base.OnCreateView(inflater, container, savedInstanceState);
var view = this.BindingInflate(Resource.Layout.MainView, null);
HasOptionsMenu = true;
var cardRecyclerView = view.FindViewById<MvxRecyclerView>(Resource.Id.myRecyclerView);
if (cardRecyclerView != null)
{
cardRecyclerView.HasFixedSize = false;
var layoutManager = new LinearLayoutManager(Activity);
cardRecyclerView.SetLayoutManager(layoutManager);
}
return view;
}