Home > OS >  How to use oxyplot with DataBinding in wpf
How to use oxyplot with DataBinding in wpf

Time:12-27

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 :(

CodePudding user response:

After searching and thinking, I finally came up with this idea: instead of downloading from NuGet package manager which results in UI dependency for "ViewModel", just download required source code from GitHub library and add it to your "ViewModel" project and use it happily.

CodePudding user response:

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.

  • Related