고정 도큐멘트 (XAML로 생성 됨)가있는 DocumentViewer가 있습니다. 그런 다음 코드의 fixedDocument에 내용을 추가하고 화면에 완벽한 내용을 표시합니다.DocumentViewer에서 FixedDocument를 제거하는 방법은 무엇입니까?
내 문제는 fixedDocument에서 '이미 다른 요소의 하위'오류가 발생하는 XPS 파일을 만들려고 할 때 발생합니다.
DocumentViewer.Children.Clear 메서드를 찾을 수 없습니다. 어떻게 파일을 만들 수 있도록 fixedDocument를 제거/분리 할 수 있습니까?
public void CreateXPSFile()
{
// 1 - create xps_file
string OutputPath = baseDir + pathAdjust + "test.xps";
using (FileStream fs = File.Create(OutputPath))
{
ConvertToXps(fixedDocument, fs);
}
// open the document using the system default xps viewer
Process.Start(OutputPath);
}
public static void ConvertToXps(FixedDocument fd, Stream outputStream)
{
var package = Package.Open(outputStream, FileMode.Create);
var xpsDoc = new XpsDocument(package, CompressionOption.Normal);
XpsDocumentWriter xpsWriter = XpsDocument.CreateXpsDocumentWriter(xpsDoc);
// xps documents are built using fixed document sequences
var fixedDocSeq = new FixedDocumentSequence();
var docRef = new DocumentReference();
docRef.BeginInit();
docRef.SetDocument(fd);
docRef.EndInit();
((IAddChild)fixedDocSeq).AddChild(docRef); <<<<<----- Error occurs here
// write out our fixed document to xps
xpsWriter.Write(fixedDocSeq.DocumentPaginator);
xpsDoc.Close();
package.Close();
}
감사