The purpose of this code is open image file in a page and display it in another page. I had tried set ViewModel by using Singleton Pattern, but it didn't work.... If I integrate to one View, it can display the image correctly. But I need to separate the views. I have no idea what's wrong in this MVVM code....and how to fix it? Please point me how can I do or let me know what keyword I can search the toturial/sample. Thank you all. -- The OpenFile button is on DisplayControlView and display on DisplayView. The View Schema is as below: MainWindow.xaml (window) | |__ReviewView.xaml (page) | |__DisplayControlView.xaml (page) | |__DisplayPanelView.xaml (page) | |__DisplayView.xaml (page) -- DisplayControlView.xaml
...
...
-- DisplayView.xaml
...
...
-- DisplayViewModel.cs
class DisplayViewModel : ViewModelBase
{
private DisplayImageModel image { get; set; }
private ObservableCollection imagelist = new ObservableCollection();
public ObservableCollection ImageList
{
get { return imagelist; }
set
{
imagelist = value;
OnPropertyChanged();
}
}
public string ImagePath
{
get { return image.Path; }
set
{
if (image.Path != value)
{
image.Path = value;
OnPropertyChanged();
}
}
}
public DisplayViewModel()
{
image = new DisplayImageModel();
ImagePath = @"C:\\Users\\oscartsai\\Desktop\\lenna.png";
}
public bool CanExecute()
{
return true;
}
public RelayCommand OpenFile
{
get { return new RelayCommand(openFile, CanExecute); }
}
private void openFile()
{
string\[\] picExtName = new string\[\] { ".PNG", ".JPG", "JEPG", "BMP" };
OpenFileDialog dlgOpenFile = new OpenFileDialog()
{ Filter = "Picture|\*.jpg;\*.jpeg;\*.bmp;\*.png|All File|\*.\*" };
if (dlgOpenFile.ShowDialog() != true)
{
return;
}
if (picExtName.Any(System.IO.Path.GetExtension(dlgO