private async Task OpenFileAsync(object parameter) { //TODO: if opening with dirty content (not saving yet) OpenFileDialog openFile = new OpenFileDialog(); openFile.Filter = "XAML Files (*.xaml)|*.xaml|RichText Files (*.rtf)|*.rtf|Text Files (*txt)|*.txt|All Files (*.*)|*.*"; string openedFilaName = ""; if (openFile.ShowDialog() == true) { string parsedXamlString = ""; openedFilaName = openFile.FileName; try { parsedXamlString = await File.ReadAllTextAsync(openedFilaName, Encoding.UTF8); } catch (Exception ex) { // error opening files then pop out messagebox MessageBox.Show(Application.Current.MainWindow, $"Error happened while opening and parsing files\r\n{ex.Message}", $"{nameof(RootViewModel.TextEditorPanelViewModel)} Error", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK); return; } //attribute parsedstring to viewmodel and record name await Application.Current.Dispatcher.BeginInvoke(() => { RootViewModel.TextEditorPanelViewModel.OpenedFileName = openedFilaName; RootViewModel.TextEditorPanelViewModel.BackUpNotes = parsedXamlString; RootViewModel.TextEditorPanelViewModel.Notes = parsedXamlString; RootViewModel.UpdateFormattedWindowTitle(); }); } }
public AllCommands(RootViewModel viewModel) { RootViewModel = viewModel; }
protected AttachedViewModels(RootViewModel root) { Root = root; }