I am trying to open a file dialog by pressing a button on view and view call a command "OpenFileDialog" which is defined in viewmodel. That method send a message to view to open the "Microsoft.Win32.OpenFileDialog()" and now I want to communicate the result of OpenFileDialog to ViewModel.
ViewModel
public ICommand OpenFileCommand {
get { return new RelayCommand( ( ) => OpenFileCommandExecute( ), ( ) => true ); }
}
private void OpenFileCommandExecute( ) {
Messenger.Default.Send( "OpenfileDialog" );
}
View
Messenger.Default.Register( this, "OpenFileDialog", openFileDialog) ;
private void openFileDialog( ) {
OpenFileDialog OFP = new OpenFileDialog( );
var kk = OFP.ShowDialog( );
}
I want to communicate the selected file path to view model. I am using MVVM Light Toolkit and WPF. My code is not in working condition.