2011-07-27 3 views
0

고정 도큐멘트 (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(); 
    } 

감사

답변

2

그냥 null로 문서를 설정 할 수 있어야한다 :

은 완성도, 여기에 오류가 메신저 코드입니다.

DocumentViewer dv; 
dv.Document = null; 
0

그런 다음 dv.Document = null을 설정 DV에 XPS를로드하지 않기 때문에, 트릭을하지 않을 수도 있습니다. 오히려 Process.Start (OutputPath); xps를 DVD에로드하십시오. 또는 프로세스를 닫을 수 있도록 프로세스에 이름을 지정할 수 있습니다. 하지만 나는 dv에 명시 적으로로드 할 것입니다.

 System.Diagnostics.Process myProcess = new System.Diagnostics.Process(); 
     myProcess.StartInfo.FileName = "C:\\HelloWorld.exe"; 
     myProcess.StartInfo.CreateNoWindow = true; 
     myProcess.Start(); 
     // ... 
     myProcess.Close(); 
관련 문제