<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="600" Width="800">
<TabControl>
<TabItem Header="Fixed Document">
<DockPanel>
<Button DockPanel.Dock="Bottom" Content="Open..." Click="btnOpenFlowDoc_Click"/>
<DocumentViewer x:Name="dvDocumentViewer" />
</DockPanel>
</TabItem>
</TabControl>
</Window>
//File:Window.xaml.cs
using System;
using System.IO;
using System.Windows;
using System.Windows.Documents;
using System.Windows.Markup;
using System.Windows.Xps.Packaging;
using System.Xml;
using Microsoft.Win32;
namespace WpfApplication1
{
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
private void btnOpenFlowDoc_Click(object sender, RoutedEventArgs e)
{
Stream file = file = File.OpenRead("c:\\b.xps");
TextReader reader = new StreamReader(file);
XmlTextReader xmlReader = new XmlTextReader(reader);
FlowDocument flowDocument = XamlReader.Load(xmlReader) as FlowDocument;
dvDocumentViewer.Document = flowDocument;
}
}
}
|