-1

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

Inevitable
  • 37
  • 1
  • 5
  • There are multiple Oxyplot nuget packages. Importing Oxyplot.Core in the ViewModel looks fine for me. Which classes from the other packages (e.g. Oxyplot.Wpf) do you need in the ViewModel code? – Klaus Gütter Dec 27 '22 at 06:44
  • Yes, @KlausGütter I've checked them out and found the solution. thank you for your kind comment :) – Inevitable Dec 27 '22 at 14:35

1 Answers1

1

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.

Daveed
  • 131
  • 1
  • 9
  • Thank you . yes, I've encountered the problems you've mentioned. I tried your solution and everything is perfect now. :) – Inevitable Dec 27 '22 at 14:34