Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,691 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
how to add FixedPage to DocumentViewer
Hi, in .NET Core 3.1. it work fine:
<Window x:Class="WpfApp1.Window02"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp02"
mc:Ignorable="d"
Title="Window02" Height="450" Width="800">
<Window.DataContext>
<local:ViewModel/>
</Window.DataContext>
<Grid>
<DocumentViewer Document="{Binding Doc}"/>
</Grid>
</Window>
-----------------------------------------------
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
namespace WpfApp02
{
public class ViewModel
{
public ViewModel()
{
Doc = RenderDocument();
}
public IDocumentPaginatorSource Doc { get; set; }
public FixedDocument RenderDocument()
{
FixedDocument fd = new FixedDocument();
PageContent pc = new PageContent();
FixedPage fp = new FixedPage();
TextBlock tb = new TextBlock();
// add some text to a TextBox object
tb.Text = "This is some test text";
// add the text box to the FixedPage
fp.Children.Add(tb);
// ,add the FixedPage to the PageContent
pc.Child = fp;
// add the PageContent to the FixedDocument
fd.Pages.Add(pc);
return fd;
}
}
}
Hi, try following demo:
<Window x:Class="Window031"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp1.WpfApp031"
mc:Ignorable="d"
Title="Window031" Height="450" Width="800">
<Window.DataContext>
<local:ViewModel/>
</Window.DataContext>
<Grid>
<DocumentViewer Document="{Binding Doc}"/>
</Grid>
</Window>
Namespace WpfApp031
Public Class ViewModel
Public Sub New()
Doc = RenderDocument()
End Sub
Public Property Doc As IDocumentPaginatorSource
Public Function RenderDocument() As FixedDocument
Dim fd As New FixedDocument()
Dim pc As New PageContent()
Dim fp As New FixedPage()
Dim tb As New TextBlock()
' add some text to a TextBox object
tb.Text = "This is some test text"
' add the text box to the FixedPage
fp.Children.Add(tb)
',add the FixedPage to the PageContent
pc.Child = fp
' add the PageContent to the FixedDocument
fd.Pages.Add(pc)
Return fd
End Function
End Class
End Namespace