I recently started a small project to freshen up the little wpf knowledge i got and to try out new stuff. I got interested in MvvmCross but I wanted to keep it small for the time being. My goal is a simple image manipulator; image to ascii, recolor and whatnot ...
My setup: Mvx Core Library (.NET Standard 2.0)
- MainViewModel - has method OpenFileDialog_Clicked which is fed into openFileDialogCommand
Wpf application (.NET Core 3.1)
- MainView - has a menu with a button that's bound to the openFileDialogCommand on MainViewModel
The wall I ran into: Trying to get a hold of OpenFileDialog (namespace: Microsoft.Win32) to do this:
public void OpenFile_Clicked()
{
Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
Nullable<bool> result = dlg.ShowDialog();
if(result) {
// big cash prize
}
}
I specified the namespace because I found several articles talking about missing references on OpenFileDialog. In my case the awnser was .NET Standard. OpenFileDialog just doesn't exist there and that's exactly my problem. How am I supposed to call OpenFileDialog in my ViewModel when the Core library has to be of type .NET Standard? Wouldn't a dependency on the wpf project ruin the entire mvvm pattern?! To be quite honest: I have read the entire mvx documentation and found a few leads but my wpf/mvvm/xaml understanding extends to maybe a third of it. The MvvmCross Inversion of Control documentation looked useful to me but I still don't get how this would work in my case. The given examples https://www.mvvmcross.com/documentation/fundamentals/inversion-of-control-ioc?scroll=43 don't show where these interfaces are located and to me it all breaks down to the fact that I somehow need to get OpenFileDialog out of the wpf project into the core project.
System.Windows.Forms.dll
assembly. – BionicCode