namespace Hotel.Model { public class MainModel { public MainModel() { } public bool ConvertImageData(string uriSource, Image imageSource) { try { BitmapImage bitImage = new BitmapImage(); bitImage.BeginInit(); bitImage.UriSource = new Uri(uriSource); bitImage.EndInit(); imageSource.Source = bitImage; } catch (Exception e) { MessageBox.Show(e.Source.ToString()); //MessageBox.Show("Select an appropriate File Type."); } return true; } public bool GetFileData(string path) { OpenFileDialog dlg = new OpenFileDialog(); dlg.Filter = @"Picture File (*.jpg; *.jpeg; *.gif; *.bmp)|*.jpg; *.jpeg; *.gif; *.bmp | All Files (*.*)|*.*"; dlg.Title = "Insert a Hotel Image"; if (dlg.ShowDialog() == true) { path = dlg.FileName; } return true; } } }
namespace Hotel.ViewModel.ViewModels{ public class EntryViewModel : BaseViewModel { private readonly MainModel model; private RelayCommand imageCommand; public EntryViewModel() { model = new MainModel(); } public void GetImage() { /* * Problem lies here... * How do I get the selected file path based on the textbox in my view * How do I get the name of the Image Control created in my view */ model.ConvertImageData(entryFilePath, entryImage); } public ICommand OpenImageCommand { get { if (imageCommand == null) { imageCommand = new RelayCommand(param => GetImage()); } return imageCommand; } } }}