我有一个带有绑定模板的列表视图。我有一个用于绑定到列表视图的绘图模型列表。我的PlotView在模板中,我将PlotModel绑定到PlotView。
一切都在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)
{
}
}
}
有什么建议吗?
一个绘图模型不能在多个视图中使用。为数组中的每个项目创建模型,而不仅仅是一个视图。但是,如果它适用于Android,则可能只需要干净安装该应用程序即可在已解决问题的情况下进行更改。