Cannot create WPF control

Oystein Bjorke 10 years ago 0
This discussion was imported from CodePlex

starrynite1959 wrote at 2012-07-19 23:29:

This looks like a great tool, but I'm having a hard time getting to first base.  I'm a newbie with WPF, though.  I'm using VS 2010, and used NuGet to install the OxyPlot packages into my project.  OxyPlot, OxyPlot.Wpf and others now show up in my References.

The second bullet step I'm to do is to "Create a PlotModel in your ViewModel."  What the heck is a ViewModel?

In my XAML, I added a line

xmlns:oxy="clr-namespace:OxyPlot.Wpf;assembly=OxyPlot.Wpf"

in my Window element.  Then in my Grid element beneath, I added

<oxy:Plot Model="{Binding myPlotModel}" Height="401" HorizontalAlignment="Left" Margin="222,12,0,0" VerticalAlignment="Top" IsEnabled="False" Background="#FFF2F296" BorderThickness="1" Width="573"/>


Then back in my MainWindow c# code, I added the WPFExample1 code you have, but when I build it complains that 'myPlotModel' does not exist in the current context.  I then added a Name="myPlotModel" attribute in the XAML and it no longer complained, but in the last line -- myPlotModel = temp; -- it gave me a type conversion error, saying that it can't convert OxyPlot.PlotModel to OxyPlot.Wpf.Plot.

I'm guessing I'm doing some basic VS or C# mis-step, that has nothing to do with OxyPlot, but I've played around with OxyPlot and OxyPlot.Wpf references and I get one error or another.

Sorry for taking your time on a noob question, but what am I doing wrong in the package references and/or XAML?

Thanx.


starrynite1959 wrote at 2012-07-24 18:36:

So the "ViewModel" referred to is the new MVVM religion?


asychow wrote at 2012-07-27 11:36:

Plot and PlotModel are completely different. You can't assign an instance of PlotModel to a Plot.

You should define myPlotModel in a ViewModel and assign the DataContext of the View (the MainWindow) to the ViewModel.

For more details, refer to the examples in the source code.


starrynite1959 wrote at 2012-07-27 14:54:

Yeah, somehow I missed a statement on oxyplot.codeplex.com that there were examples in the Source Code.  I figured that out two days ago and have been playing.  The code above that I tried to use was based on what is shown on oxyplot.codeplex.com/wikipage?title=WpfExample1&referringTitle=Home.  Thanx.


objo wrote at 2012-08-09 00:13:

Yes, most WPF/SL examples are using the MVVM design pattern. I will not add examples using named plot controls (even if it is possible) as I don't think this is good practice.

Will try to improve the 'getting started' documentation as soon as I get time! 


_Noctis_ wrote at 2013-11-05 13:42:

I'll take it time was not kind to you, good ser? :)

objo wrote at 2013-11-05 18:55:

:) You're right! Time is passing more quickly than it used to! But documentation is coming, I am working on it :) If anyone really likes writing documentation and would like to give a hand, please shout out!

_Noctis_ wrote at 2013-11-06 03:40:

Howling into the night ...

Nobody likes writing documentation, everybody loves reading it and complains if it's not there ...
That's what differentiates good code from bad code ...

Having said that, how could I help?

objo wrote at 2013-11-06 23:04:

I will submit what I have 'very' soon! The documentation will be written in wiki syntax as plain text files under a new ~/Documentation folder. Create a fork and make a pull request when ready. The build machine will convert the wiki files to html, chm and pdf, and upload to http://oxyplot.org/doc. The API documentation will be generated from the XML comments and also included there. This should make everything googlable!