编程语言
首页 > 编程语言> > c# – 与WPF中的Oxyplot进行数据绑定

c# – 与WPF中的Oxyplot进行数据绑定

作者:互联网

我正在努力解决有关WPF项目中OxyPlot的几个问题.

首先,我可以使用Plot类或PlotView类.这两个班级有什么区别?

理想情况下,我想对模型(或至少部分模型)和数据使用数据绑定.

如果我使用PlotView,我可以使用Binding作为模型,如下所示:

<oxy:PlotView Model="{Binding Model}"/>

如果我使用Plot,我可以使用数据绑定数据,如

<oxy:Plot>
  <oxy:Plot.Series>
    <oxy:LineSeries ItemsSource="{Binding Points}" />
  </oxy:Plot.Series>
</oxy:Plot>

我可以让这两个都工作,但是有没有办法对模型和数据使用Binding?

如果我使用Plot类和Binding来获取数据,我至少会喜欢使用Binding作为LineColor,就像这样

<oxy:Plot>
  <oxy:Plot.Series>
    <oxy:LineSeries ItemsSource="{Binding Points}" 
                        DataFieldX="X" 
                        DataFieldY="Y"
                        StrokeThickness="2"
                        MarkerSize="0"
                        LineStyle="Solid"
                        Color="{Binding LineColor}"
                        MarkerType="None"/>
  </oxy:Plot.Series>
</oxy:Plot>

我根本无法工作.曲线始终为绿色.我的LineColor属性使用类型OxyColor定义.这是错误的类型吗?

我知道我在同一篇文章中提出了几个问题,但我认为它们是密切相关的.

解决方法:

首先,我可以使用Plot类或PlotView类.这两个班级有什么区别?

我认为你看到了你的例子中的差异,如果你想绑定到模型,你必须使用oxy:PlotView.如果你想绑定到lineseries,那么你将不得不使用oxy:Plot控件.

我可以让这两个都工作,但是有没有办法对模型和数据使用Binding?

不,如最后一句所述,你不能同时绑定两者,但你可以像这样在你的模型中添加lineseries(在你的例子中):

PlotModel model = new PlotModel();
List<DataPoint> Points = new List<DataPoint>();

LineSeries lineserie = new LineSeries
{
    ItemsSource = Points,
    DataFieldX = "x",
    DataFieldY = "Y",
    StrokeThickness = 2,
    MarkerSize = 0,
    LineStyle = LineStyle.Solid,
    Color = OxyColors.White,
    MarkerType = MarkerType.None,
};

model.Series.Add(lineserie);

然后使用oxy:PlotView绑定到模型,就是这样.如果要修改处理绘图行为的参数,则必须将PlotController属性绑定到(以防万一,以备将来工作).

编辑:

Oystein Bjorke(OxyPlot创建者)这样说,回答了两个问题:

The PlotView component is now similar on all platforms, it contains
only Model and Controller properties. The Plot control let you
define axes, series, annotations etc. and this should only be
available in XAML-based platforms.

链接:http://discussion.oxyplot.org/topics/240-cant-define-axes-in-xaml/

标签:c,data-binding,wpf,xaml,oxyplot
来源: https://codeday.me/bug/20190628/1311402.html