菜鸟教程小白 发表于 2022-12-11 19:44:31

c# - 如何在 Xamarin.Forms IOS 的 ListView 控件中使用 OxyPlot 条形图?


                                            <p><p>我有一个带有绑定(bind)模板的 ListView。我有一个 PlotModels 列表,用于绑定(bind)到 ListView 。
我的 PlotView 位于我将 PlotModel 绑定(bind)到 PlotView 的模板内。</p>

<p>在 Android 中一切运行顺利。但问题是我收到一个错误<strong>“PlotModel 已被其他一些 PlotView 控件使用。”</strong>。
当我尝试在 IOS 上运行它时。</p>

<p>//我的内容页面</p>

<pre><code>public MyConstructor()
{
List&lt;MyChart&gt; charts = new List&lt;MyChart&gt;();
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; }
}
</code></pre>

<p>//我的查看单元格</p>

<pre><code>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, &#34;PlotModel&#34;);
                View = plotView;               
            }
            catch (Exception ex)
            {
            }
      }
}
</code></pre>

<p>有什么建议吗?</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p> <a href="http://docs.oxyplot.org/en/latest/models/plot-model.html" rel="noreferrer noopener nofollow">A PlotModel cannot be used in more than one view</a> .为数组中的每个项目创建模型,而不仅仅是一个 View 。但如果它适用于 Android,如果您已经解决了问题,您可能只需要全新安装应用程序即可获得更改。</p></p>
                                   
                                                <p style="font-size: 20px;">关于c# - 如何在 Xamarin.Forms IOS 的 ListView 控件中使用 OxyPlot 条形图?,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/44173022/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/44173022/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: c# - 如何在 Xamarin.Forms IOS 的 ListView 控件中使用 OxyPlot 条形图?