Kugelschreiber_Y Kugelschreiber_Y - 11 months ago 146
C# Question

Oxyplot does not display plots in WPF view

I'm working with OxyPlot in WPF. Trying to display PlotModels in a UI.
Sometimes the plot is displayed in the UI and sometimes not.

This code is used to initialize the

by a


this.pm = setUpModel();

With the methods:

private PlotModel _pm;
public PlotModel pm
get { return _pm; }
set { _pm= value; RaisePropertyChanged("pm"); }

private PlotModel setUpModel()
PlotModel pm = new PlotModel();
pm.IsLegendVisible = false;
var xAxis= new CategoryAxis();
var valueAxis = new LinearAxis();
return pm ;

//tbl holds the data in the second column
private void data2plot(DataTable tbl)
var series = new OxyPlot.Series.LineSeries();
int i = 0;
foreach (DataRow row in tbl.Rows)
double val = double.Parse(row[1].ToString());
series.Points.Add(new DataPoint(i, val));


Code used in View to initialize the model:

<Grid HorizontalAlignment="Left" Height="205" Margin="10,117,0,0" VerticalAlignment="Top" Width="308">
<oxypl:PlotView x:Name="plot" Model="{Binding pm,UpdateSourceTrigger=PropertyChanged}" Margin="10" Grid.Row="1">

with the following references

DataContext="{Binding Source={StaticResource Locator}, Path=ViewModel}"

The Binding works, so I guess there have to be a problem with my

I don't know if this is relevant, but the
DataTable tbl
is initialized by the
class (with

Answer Source

When you add to your pm member, the value of pm is not being updated - it's the content of that member that is updated, i.e. the setter is never called, so the RaisePropertyChanged event is never emitted and the view isn't notified of any change. Suggest you build a local set of data and then overwrite pm with a complete set of data at the end, or emit a RaisePropertyChanged event when you're done.

The reason that it is working sometimes I would guess is that the first (and only) time the view reads the content back from the viewmodel you've already populated it, so you see something, but then no updates.