2
我有一個綁定模板的ListView。我有一個PlotModels列表,我正在使用它來綁定到列表視圖。 而我的PlotView是在模板中,我將PlotModel綁定到PlotView。如何在Xamarin.Forms IOS的listview控件中使用OxyPlot條形圖?
在Android中,一切都運行平穩。但問題是我得到一個錯誤「PlotModel已被一些其他PlotView控件使用」。。 當我試圖在IOS上運行它。
//我的內容頁面
public MyConstructor()
{
List<MyChart> charts = new List<MyChart>();
charts.Add(new MyChart { PlotModel = PlotModel1 });
charts.Add(new MyChart { PlotModel = PlotModel2 });
charts.Add(new MyChart { PlotModel = PlotModel3 });
charts.Add(new MyChart { PlotModel = PlotModel4 });
ListView lvPlots = new ListView(ListViewCachingStrategy.RetainElement)
{
ItemsSource = charts,
ItemTemplate = new DataTemplate(typeof(NewDashboardSubCell)),
HasUnevenRows = true
};
Content = lvPlots;
}
public class MyChart
{
public MyPlotModel PlotModel { get; set; }
}
//我查看電池
public class NewDashboardSubCell : ViewCell
{
PlotView plotView;
public NewDashboardSubCell()
{
try
{
plotView = new PlotView
{
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.FillAndExpand,
IsVisible = true,
IsEnabled = true,
HeightRequest = App.ScreenHeight - 100,
WidthRequest = App.ScreenWidth - 40
};
plotView.SetBinding(PlotView.ModelProperty, "PlotModel");
View = plotView;
}
catch (Exception ex)
{
}
}
}
有什麼建議?
我對不同的視圖使用不同的plotmodel。所以沒有辦法爲一個以上的視圖使用單個繪圖模型。你可以檢查我的代碼。 –