OGeek|极客世界-中国程序员成长平台

标题: c# - 如何在 Xamarin.Forms IOS 的 ListView 控件中使用 OxyPlot 条形图? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 19:44
标题: c# - 如何在 Xamarin.Forms IOS 的 ListView 控件中使用 OxyPlot 条形图?

我有一个带有绑定(bind)模板的 ListView。我有一个 PlotModels 列表,用于绑定(bind)到 ListView 。 我的 PlotView 位于我将 PlotModel 绑定(bind)到 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, "lotModel");
                View = plotView;                
            }
            catch (Exception ex)
            {
            }
        }
}

有什么建议吗?



Best Answer-推荐答案


A PlotModel cannot be used in more than one view .为数组中的每个项目创建模型,而不仅仅是一个 View 。但如果它适用于 Android,如果您已经解决了问题,您可能只需要全新安装应用程序即可获得更改。

关于c# - 如何在 Xamarin.Forms IOS 的 ListView 控件中使用 OxyPlot 条形图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44173022/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4