wpf中为flowDocument添加注释

<Window   
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:a="clr-namespace:System.Windows.Annotations;assembly=PresentationFramework"
    Title="FlowDocumentReader + Annotations"
  x:Class="Window1" Initialized="OnInitialized" Closed="OnClosed">
  <StackPanel>
    <StackPanel Orientation="Horizontal">
      <Label>Control Annotations:</Label>
      <Button Command="a:AnnotationService.CreateTextStickyNoteCommand"
         CommandTarget="{Binding ElementName=reader}">Create Text Note</Button>
      <Button Command="a:AnnotationService.CreateInkStickyNoteCommand" CommandTarget="{Binding ElementName=reader}">
        Create Ink Note
      </Button>
      <Button Command="a:AnnotationService.DeleteStickyNotesCommand" CommandTarget="{Binding ElementName=reader}">
        Remove Note
      </Button>
      <Button Command="a:AnnotationService.CreateHighlightCommand"  CommandTarget="{Binding ElementName=reader}">
        Create Yellow Highlight
      </Button>
      <Button Command="a:AnnotationService.ClearHighlightsCommand" CommandTarget="{Binding ElementName=reader}">
        Remove Highlight
      </Button>
    </StackPanel>

    <FlowDocumentReader x:Name="reader">
      <FlowDocument>
        <Paragraph FontSize="22" FontWeight="Bold">Chapter 1</Paragraph>
        <Paragraph FontSize="35" FontWeight="Bold">Why WPF?</Paragraph>
        <Paragraph>
          In movies and on TV, the main characters are typically
          an exaggeration of the people you encounter in real life.
          They're more attractive, they react quicker, and they
          somehow always know exactly what to do. The same could
          be said about the software they use.
        </Paragraph>
        <Paragraph>
          This first struck me back in 1994 when watching the movie
          Disclosure, starring Michael Douglas, Demi Moore, and an
          email program that looks nothing like Microsoft Outlook!
          Throughout the movie, we're treated to various visual
          features of the program: a spinning three-dimensional "e,"
          messages that unfold when you open them and crumple
          when you delete them, hints of inking support, and slick
          animations when you print messages. (The email program
          isn't even the most unrealistic software in the movie. I'll
          just say "virtual reality database" and leave it at that.)
        </Paragraph>
        <Paragraph>
          Usability issues aside, Hollywood has been telling us for a
          long time that software in the real world isn't as
          compelling as it should be. You can probably think of
          several examples on your own of TV shows and movies
          with comically unrealistic software. But real-world software
          is starting to catch up to Hollywood's standards! You can
          already see it in traditional operating systems (such as Mac
          OS and more recently Windows Vista), in software for
          devices such as TiVo or Xbox, and on the Web thanks to
          Adobe Flash. Users have increasing expectations for the
          experience of using software, and companies are spending
          a great deal of time and money on user interfaces that
          differentiate themselves from the competition.
        </Paragraph>
        <Paragraph>
          Microsoft now has a solution for helping people create 21st-century software that meets
          these high demands, using less time and less money. This solution is Windows
          Presentation Foundation (WPF).
        </Paragraph>
      </FlowDocument>
    </FlowDocumentReader>
  </StackPanel>
</Window>

 

protected void OnInitialized(object sender, EventArgs e)
    {
        // Enable and load annotations
        AnnotationService service = AnnotationService.GetService(reader);
        if (service == null)
        {
            stream = new FileStream("storage.xml", FileMode.OpenOrCreate);
            service = new AnnotationService(reader);
            AnnotationStore store = new XmlStreamStore(stream);
            service.Enable(store);
        }
    }

    protected void OnClosed(object sender, EventArgs e)
    {
        // Disable and save annotations
        AnnotationService service = AnnotationService.GetService(reader);
        if (service != null && service.IsEnabled)
        {
            service.Store.Flush();
            service.Disable();
            stream.Close();
        }
    }

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值