Can't get document to display in EditorDocumentViewer

SyntaxEditor for WPF Forum

Posted 5 years ago by Hank Drews
Version: 14.2.0610
Platform: .NET 4.5
Environment: Windows 8 (64-bit)
Avatar

I have an EditorDocumentViewer placed as content to a BackstageTab labeled "Print".   I populate the Document property with the a FixedDocument created by the actively displayed syntaxeditor using the "editor.PrintSettings.CreateFixedDocument(editor)" method.   However the document does not display on the screen.  All of the buttons become active and when I click the Print button the correct document prints.  Here is the snipped of code I use to populate the Document property:

 

      private void PrintBackstageTabBorder_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e) {
         var visible = e.NewValue as bool?;
         if(visible != null && (DockingSite.ActiveWindow != null && (bool) visible)) {
            var editor = DockingSite.ActiveWindow.Content as SyntaxEditor;
            if(editor != null) {
               editor.PrintSettings.DocumentTitle = editor.Document.FileName;
               editor.PrintSettings.IsDocumentTitleMarginVisible = true;
               editor.PrintSettings.IsLineNumberMarginVisible = App.Preferences.LineNumberMargin;
               editor.PrintSettings.IsPageNumberMarginVisible = true;
               editor.PrintSettings.IsSyntaxHighlightingEnabled = true;
               editor.PrintSettings.IsWordWrapGlyphMarginVisible = true;
               editor.PrintSettings.IsWhitespaceVisible = App.Preferences.Whitespace;

               Viewer.Document = editor.PrintSettings.CreateFixedDocument(editor);
            }
         }
      }

 

And here is XAML for the EditorDocumentViewer:

               <ribbon:BackstageTab x:Name="PrintBackstageTab" Header="Print" KeyTipAccessText="P">
                  <Border x:Name="PrintBackstageTabBorder" Style="{StaticResource ContentBoxBorderStyle}" IsVisibleChanged="PrintBackstageTabBorder_IsVisibleChanged">
                     <syntaxeditor:EditorDocumentViewer x:Name="Viewer"
                                        Margin="15,0,0,0"
                                        DockPanel.Dock="Right" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" />
                  </Border>
               </ribbon:BackstageTab>

 

Any help would be appreciated.   This works in the sample provided with the controls, but I can't seem to get it to work for me though.

Comments (2)

Posted 5 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Hank,

I did a very simple test where I put a Ribbon, SyntaxEditor, and a Button on a Window.  In response to the button click I did the code in your "if (editor != null)" block.  Then I opened the Ribbon and saw the EditorDocumentViewer content fine.

My guess is that your event that you are creating the preview in is not good (maybe it needs to be done sooner), or something in your layout code within the ribbon:BackstageTab is not good.  It's more likely the first thing, which you could test by doing that logic in a button click event handler instead.


Actipro Software Support

Posted 5 years ago by Hank Drews
Avatar

Your right about the event.   I do not know why, but when I moved my code for setting the viewer to my event for when a document window becomes active (I'm using the Docking control as well), it works.

 

Thank you, your response pointed me in the right direction.

The latest build of this product (v2019.1 build 0683) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.