WPF注释加载到XPS

问题描述 投票:0回答:1

在调查将AnnotationService类与XML Paper Specification(XPS)结合使用的过程中,我尝试保存和加载创建的注释。使用Save批注-一切都很简单(它是described on microsoft),但是有了负载-没有任何信息(缺少任何方法“ Read” /“ Write”)。对于AnnotationResource类,存在一些“读取” /“写入”方法,但是我不明白如何将其用于加载注释,以便与Annotation Service Class一起使用。如果您知道,这将是谁的工作,很有趣,值得一看?

c# wpf annotations xps
1个回答
0
投票

EnableAnnotations()-简单的启用注释(临时存储在MemoryStream中;]]

    SaveAnnotations()-将注释保存到FileStream;
  • LoadAnnotations()-从FileStream加载注释并启用注释;
  • _storeMemory.Position = 0;上没有注释的注释无法正确保存或加载
  • public class MyAnnotationStore { XmlStreamStore _storeXML; MemoryStream _storeMemory; AnnotationService _anoService; public MyAnnotationStore(FlowDocumentReader myDocumentReader) { // Create the AnnotationService object that works // with our FlowDocumentReader. _anoService = new AnnotationService(myDocumentReader); // Create a MemoryStream which will hold the annotations. _storeMemory = new MemoryStream(); } public void EnableAnnotations() { // Now, create a XML-based store based on the MemoryStream. // You could use this object to programmatically add, delete // or find annotations. _storeXML = new XmlStreamStore(_storeMemory); // Enable the annotation services. _anoService.Enable(_storeXML); } public void SaveAnnotations() { _storeXML.Flush(); _storeMemory.Flush(); using (FileStream fileStream = new FileStream("StickNotes.xml", FileMode.Create)) { _storeMemory.Position = 0; _storeMemory.CopyTo(fileStream); } } public void LoadAnnotations() { FileStream fileStream = null; try { fileStream = new FileStream("StickNotes.xml", FileMode.Open, FileAccess.Read); fileStream.CopyTo(_storeMemory); _storeMemory.Position = 0; } catch (Exception ex) { MessageBox.Show(ex.Message, "Error File Read", MessageBoxButton.OK, MessageBoxImage.Error); } finally { if (fileStream != null) fileStream.Close(); } // Enable the annotation services after loading annotations from fileStream EnableAnnotations(); } }

    用于测试目的的后台代码

        public partial class MainWindow : Window
        {
            MyAnnotationStore anoStore;
    
            public MainWindow()
            {
                InitializeComponent();
                // Create object for manipulate with annotations in myDocumentReader (load and create)
                anoStore = new MyAnnotationStore(myDocumentReader);
            }
    }
    

    和XAML

    <FlowDocumentReader x:Name="myDocumentReader" Height="238.9">
                            <FlowDocument>
                                <Section>
                                    <Paragraph>
                                        Here are some fun facts about the WPF Document API!
                                    </Paragraph>
                                </Section>
                            </FlowDocument>
                        </FlowDocumentReader>
    
  • © www.soinside.com 2019 - 2024. All rights reserved.