public void PropertyChangedEventTest() { var viewModel = Container.GetExportedValue <RichTextViewModel>(); var documentType = new RichTextDocumentType(); var document = new RichTextDocument(documentType); viewModel.Document = document; Assert.AreEqual(document, viewModel.Document); AssertHelper.PropertyChangedEvent(viewModel, x => x.IsBold, () => viewModel.IsBold = true); Assert.IsTrue(viewModel.IsBold); AssertHelper.PropertyChangedEvent(viewModel, x => x.IsItalic, () => viewModel.IsItalic = true); Assert.IsTrue(viewModel.IsItalic); AssertHelper.PropertyChangedEvent(viewModel, x => x.IsUnderline, () => viewModel.IsUnderline = true); Assert.IsTrue(viewModel.IsUnderline); AssertHelper.PropertyChangedEvent(viewModel, x => x.IsNumberedList, () => viewModel.IsNumberedList = true); Assert.IsTrue(viewModel.IsNumberedList); AssertHelper.PropertyChangedEvent(viewModel, x => x.IsBulletList, () => viewModel.IsBulletList = true); Assert.IsTrue(viewModel.IsBulletList); AssertHelper.PropertyChangedEvent(viewModel, x => x.IsSpellCheckEnabled, () => viewModel.IsSpellCheckEnabled = true); Assert.IsTrue(viewModel.IsSpellCheckEnabled); }
private void ShowPrintPreview() { // We have to clone the FlowDocument before we use different pagination settings for the export. RichTextDocument document = (RichTextDocument)fileService.ActiveDocument; FlowDocument clone = document.CloneContent(); clone.ColumnWidth = double.PositiveInfinity; // Create a package for the XPS document MemoryStream packageStream = new MemoryStream(); package = Package.Open(packageStream, FileMode.Create, FileAccess.ReadWrite); // Create a XPS document with the path "pack://temp.xps" PackageStore.AddPackage(new Uri(PackagePath), package); xpsDocument = new XpsDocument(package, CompressionOption.SuperFast, PackagePath); // Serialize the XPS document XpsSerializationManager serializer = new XpsSerializationManager(new XpsPackagingPolicy(xpsDocument), false); DocumentPaginator paginator = ((IDocumentPaginatorSource)clone).DocumentPaginator; serializer.SaveAsXaml(paginator); // Get the fixed document sequence FixedDocumentSequence documentSequence = xpsDocument.GetFixedDocumentSequence(); // Create and show the print preview view PrintPreviewViewModel printPreviewViewModel = printPreviewViewModelFactory.CreateExport().Value; printPreviewViewModel.Document = documentSequence; previousView = shellViewModel.ContentView; shellViewModel.ContentView = printPreviewViewModel.View; shellViewModel.IsPrintPreviewVisible = true; printPreviewCommand.RaiseCanExecuteChanged(); }
public void ShowPrintDocument() { var viewModel = Get <PrintPreviewViewModel>(); var document = new RichTextDocument(new RichTextDocumentType()); viewModel.Document = document; Assert.AreEqual(document, viewModel.Document); }
private void ExecuteShowFontDialog(RichTextDocument document) { NavigationParameters parameters = new NavigationParameters(); parameters.Add(FontDialogParameters.CharacterSettingsKey, document.GetCommonCharacterSettings(this.Selection.DocumentSpan)); this.dialogService.ShowIgDialog("FontDialogView", parameters); }
private void ExecuteShowInsertTableDialog(RichTextDocument document) { NavigationParameters parameters = new NavigationParameters(); parameters.Add(InsertTableDialogParameters.DocumentKey, document); parameters.Add(InsertTableDialogParameters.SelectionKey, this.Selection); this.dialogService.ShowIgDialog("InsertTableDialogView", parameters); }
public void NewDocumentTest() { RichTextDocumentType documentType = new RichTextDocumentType(); Assert.IsTrue(documentType.CanNew()); RichTextDocument document = documentType.New() as RichTextDocument; Assert.IsNotNull(document); Assert.AreEqual("Document 1.rtf", document.FileName); }
protected override void OnDocumentRemoved(IDocument document) { RichTextDocument richTextDocument = document as RichTextDocument; if (richTextDocument != null) { mainViewModel.DocumentViews.Remove(richTextViewModels[richTextDocument].View); richTextViewModels.Remove(richTextDocument); } }
private void PrintDocument() { if (printDialogService.ShowDialog()) { // We have to clone the FlowDocument before we use different pagination settings for the export. RichTextDocument document = (RichTextDocument)fileService.ActiveDocument; FlowDocument clone = document.CloneContent(); printDialogService.PrintDocument(((IDocumentPaginatorSource)clone).DocumentPaginator, fileService.ActiveDocument.FileName); } }
public void OnNavigatedTo(NavigationContext navigationContext) { this.document = (RichTextDocument)navigationContext.Parameters[InsertTableDialogParameters.DocumentKey]; this.selection = (Selection)navigationContext.Parameters[InsertTableDialogParameters.SelectionKey]; NumberOfColumns = 5; NumberOfRows = 2; FixedColumnWidth = 0; IsFixedColumnWidth = true; IsAutoFitToContents = false; IsAutoFitToWindow = false; }
protected override void OnDocumentAdded(IDocument document) { RichTextDocument richTextDocument = document as RichTextDocument; if (richTextDocument != null) { RichTextViewModel richTextViewModel = richTextViewModelFactory.CreateExport().Value; richTextViewModel.Document = richTextDocument; richTextViewModels.Add(richTextDocument, richTextViewModel); mainViewModel.DocumentViews.Add(richTextViewModel.View); } }
protected override IDocument OpenCore(string fileName) { var flowDocument = new FlowDocument(); var range = new TextRange(flowDocument.ContentStart, flowDocument.ContentEnd); using (var stream = new FileStream(fileName, FileMode.Open)) { range.Load(stream, DataFormats.Rtf); } var document = new RichTextDocument(this, flowDocument); documentCount++; return(document); }
protected override void OnActiveDocumentChanged(IDocument activeDocument) { if (activeDocument == null) { mainViewModel.ActiveDocumentView = null; } else { RichTextDocument richTextDocument = activeDocument as RichTextDocument; if (richTextDocument != null) { mainViewModel.ActiveDocumentView = richTextViewModels[richTextDocument].View; } } }
public HelpView() { InitializeComponent(); HideScriptErrors(WebBrowserHost, true); RichTextDocument richTextDocument = XamRichTextEditor.Document; // ReSharper disable PossibleNullReferenceException Color color = (Color)ColorConverter.ConvertFromString("#FFF4F2EE"); // ReSharper restore PossibleNullReferenceException var colorInfo = new ColorInfo(color); richTextDocument.RootNode.Settings = new DocumentSettings { Background = colorInfo, }; XamRichTextEditor.CaretColor = colorInfo; }
/// <summary> /// Creates a new <see cref="BreakingChangeRichTextDocumentFormatter"/> instance. /// </summary> public BreakingChangeRichTextDocumentFormatter() { _defaultCharacterSettings = new CharacterSettings { Bold = false, Italics = false }; _document = new RichTextDocument(); _runText = new StringBuilder(); _document.RootNode.Styles.Add((RichTextStyleBase)_document.AvailableStyles[ListStyleId].Clone()); _document.RootNode.Lists.Add(new RichTextList { Id = ListId, ListStyleId = ListStyleId, }); this.AppendLine(); }
public IRead Get(eFileType type) { IRead read = null; switch (type) { case eFileType.RichTextDocument: read = new RichTextDocument(); break; case eFileType.WordDocument: read = new WordDocument(); break; case eFileType.TextDocument: read = new TextDocument(); break; } return(read); }
public void OnNavigatedTo(NavigationContext navigationContext) { this.document = (RichTextDocument)navigationContext.Parameters[HyperlinkDialogParameters.DocumentKey]; this.selection = (Selection)navigationContext.Parameters[HyperlinkDialogParameters.SelectionKey]; HyperlinkNode[] hyperlinksInSpan = document.GetHyperlinks(this.selection.DocumentSpan).ToArray(); if (hyperlinksInSpan.Length > 0) { this.hyperlinkBeingEdited = hyperlinksInSpan[0]; this.TextToDisplay = this.hyperlinkBeingEdited.GetText(); this.Address = this.hyperlinkBeingEdited.Uri; this.ToolTipText = this.hyperlinkBeingEdited.Tooltip; this.dialogMode = HyperlinkDialogMode.EditingHyperlink; } else { if (selection.Length > 0) { this.dialogMode = HyperlinkDialogMode.MakingHyperlink; this.TextToDisplay = this.selection.Text; } else { if (this.SelectionIsWithinWord()) { selection.SelectCurrentWord(); } string textInSelection = document.GetTextInSpan(selection.DocumentSpan); if (textInSelection.Trim().Length < 1) { this.dialogMode = HyperlinkDialogMode.InsertingHyperlink; selection.Collapse(SelectionCollapseDirection.Start); } else { this.dialogMode = HyperlinkDialogMode.MakingHyperlink; this.TextToDisplay = selection.Text; } } } }
static void Document_ContentChanged(object sender, DocumentContentChangedEventArgs e) { if (e.ChangeType == Infragistics.Documents.RichText.DocumentChangeType.Content) { var xamRichTextEditor = sender as XamRichTextEditor; xamRichTextEditor.DocumentContentChanged -= Document_ContentChanged; var rtfString = (string)xamRichTextEditor.GetValue(XamRichTextEditorBehavior.InsertRtfContentProperty); RichTextDocument doc = new RichTextDocument(); var stream = new MemoryStream(Encoding.UTF8.GetBytes(rtfString)); doc.LoadFromRtf(stream); string error; xamRichTextEditor.Document.InsertContent(0, doc.RootNode, out error, true, true); } }
private void ExecuteShowInsertPictureDialog(RichTextDocument document) { if (document == null) { return; } string selectedFilePath; var filters = ShellParameters.FileDialogImageFilter; var result = dialogService.ShowOpenFileDialog(null, out selectedFilePath, filters); if (result == InteractionResult.Ok) { string error; ImageNode node = new ImageNode(); MemoryStream memStream = new MemoryStream(); JpegBitmapEncoder encoder = new JpegBitmapEncoder(); BitmapImage image = null; try { image = new BitmapImage(new Uri(String.Format(selectedFilePath), UriKind.Absolute)); } catch (NotSupportedException) { messageBoxService.Show(ResourceStrings.ResourceStrings.Text_Warning, ResourceStrings.ResourceStrings.Mg_NotSuppportedFileFormat, MessageBoxButtons.Ok); return; } encoder.Frames.Add(BitmapFrame.Create(image)); encoder.Save(memStream); node.Image = new RichTextImage(memStream.GetBuffer(), RichTextImageFormat.Jpeg); document.InsertContent(selection.DocumentSpan.Offset, node, out error); } }
private static RichTextViewModel CreateRichTextViewModel(string fileName) { return(new(new RichTextView(), new MockShellService()) { Document = new RichTextDocument(new RichTextDocumentType()) { FileName = fileName } });
private bool CanExecuteShowFormattingDialog(RichTextDocument richTextDocument) { return(richTextDocument != null && this.IsUiPartEnabled); }