I´m a total C# noob, so please be indulgent with me ;)
I´m just working on an WPF Application and want to implement my program in the MVVM-pattern. I want to write a simple HTML editor. So at first my application consists of a menu, which owns the item "File". There you should be able to select between "New", "Open", "Save", "Save As" and "Close". During my first steps with C# I wrote these functions in the CodeBehind-File of the MainWindow and it worked. But now I want to implement my program in a "cleaner" way by using the MVVM pattern. But I really have problems to understand this pattern and especially to implement the SaveDialog and the OpenDialog without CodeBehind.
private void Oeffnen_Click(object sender, RoutedEventArgs e)
{
//neuen OpenDialog anlegen
webBrowser2 = new WebBrowser();
DockPanel.SetDock(webBrowser2, Dock.Top);
this.DockPanel1.Children.Add(webBrowser2);
opendlg = new Microsoft.Win32.OpenFileDialog();
opendlg.Filter = "html files (*.html)|*.html|htm files (*.htm)|*.htm";
//opendlg.RestoreDirectory = true;
//öffne Opendialog
if (opendlg.ShowDialog() == true)
{
try
{
if (opendlg.OpenFile() != null)
{
filename = opendlg.FileName;
webBrowser2.Navigate("file:///" + filename); //Öffne html Datei
doc2 = webBrowser2.Document as IHTMLDocument2;
doc2.designMode = "On"; //Editierbarkeit aktivieren
}
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
}
}
So this is for example my CodeBehind for the FileOpen-function.
Can someone maybe explain me on the example of the Open or SaveDialog or anyway else, how to use the MVVM pattern with this kind of application?
Sorry if this question is too general. Please ask for details.
Thanks!