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。所以没有办法为一个以上的视图使用单个绘图模型。你可以检查我的代码。 –