Oxyplot - WPF使plotview无效

时间:2015-10-17 13:43:36

标签: c# wpf oxyplot

我正在使用Oxyplot作为我的WPF应用程序。我想捕获一些数据,然后我想在图表中显示它们。 我在XAML中有这段代码:

PolyBatch

和班级:

xmlns:oxy="http://oxyplot.org/wpf"


 <Window.DataContext>
        <local:MainViewModel/>
  </Window.DataContext>
  <oxy:PlotView Title="{Binding Title}" Margin="241,0,0,179" Name="Plot1" Grid.Column="2">
       <oxy:PlotView.Series>
            <oxy:LineSeries ItemsSource="{Binding Points}"/>
        </oxy:PlotView.Series>
  </oxy:PlotView>

事情是,我想要点击&#34; Second()&#34;的按钮显示情节。 它通过调用方法Second()和Plot1.InvalidatePlot(true)之后执行,但它什么都不做。 我在哪里做错了,请帮帮忙? 感谢

2 个答案:

答案 0 :(得分:1)

目前,答案可能已更改,且已为mentioned here

  
      
  • 更改PlotView控件的Model属性
  •   
  • 在PlotView控件上调用Invalidate
  •   
  • 在PlotModel上调用Invalidate
  •   

我建议您删除&#34; PropertyChanged&#34;并将其插入更新方法。

PlotModel.InvalidatePlot(true);

答案 1 :(得分:0)

更改为<oxy:LineSeries ItemsSource="{Binding Points, Mode=OneWay}"/>

这将确保对Points的更改传播到图表控件。其次,在ViewModel类中实现INotifyPropertyChanged。例如;

IList<DataPoint> _points;
public IList<DataPoint> Points { get{return _points;}; private set{ _points = value; OnPropertyChanged("Points");} }

        private void OnPropertyChanged(string p)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(p));
        }

public void Second()
    {
        this.Points.Clear();
        this.Title = "Test";

        this.Points = new List<DataPoint>();

        for (int i = 0; i <= 800; i++)
        {
            double x = (Math.PI * i) / 400;
            double y = Math.Cos(x);
            DataPoint p = new DataPoint(x, 0.5);
            Points.Add(p);
        }
        /* suggested change */
        OnPropertyChanged("Points");
    }