wpfmvvmoxyplot

How to use oxyplot with DataBinding in wpf


I'm trying to use the oxyplot library in my WPF application. also, I'm using the MVVM pattern. one of the main parts of this pattern never uses "UI" specific in the "ViewModel" project. but when I look at the examples for this library, I see people are referencing oxyplot in their "ViewModels" by this: using oxyplot;. now I have this question. how should I use this library with the MVVM pattern? now I have installed the package in my "view" project by the NuGet package manager, should I do the same for my "ViewModel" project? I think this is not good because by installing it in "ViewModel" I'm breaking the MVVM pattern. but how can I access oxyplot classes from my "ViewModel"? Thanks in advance.

I was expecting to use the oxyplot by the MVVM pattern but now I'm mixed up :(


Solution

  • your approach might work but I think you also need a value converter to convert between classes in "View" and "ViewModel" because they belong to different assemblies and also you may end up with namespace conflicts between "oxyplot" in "ViewModel" and "oxyplot" in "View" so you also have to do extra thing, for example, renaming the "oxyplot" namespace in "ViewModel" I think. The Best solution is to add "Oxyplot.Core" to your "ViewModel" and everything works fine and there is no need for extra work.