I had all manner of difficulty with the code below until I referenced this SO post and decided I must need Shadows, after which it worked just fine; I just don't really understand it. The referenced post seemed to have many adherents to the 'don't like to EVER use Shadows' group, but I don't see how the code below could be written without Shadows, nor do I understand why it ultimately was required.
There was a XAML page that defines the buttons to invoke the annotation methods and also display the FlowDocumentReader
I didn't think that was necessary for this question but can add it if necessary
Imports System.IO
Imports System.Windows.Annotations
Imports System.Windows.Annotations.Storage
Partial Public Class MainWindow
Inherits Window
Private stream As Stream
Public Sub New()
InitializeComponent()
End Sub
Protected Shadows Sub OnInitialized(sender As Object, e As EventArgs)
' Enable and load annotations
Dim service As AnnotationService = AnnotationService.GetService(reader6)
If service Is Nothing Then
stream = New FileStream("storage.xml", FileMode.OpenOrCreate)
service = New AnnotationService(reader6)
Dim store As AnnotationStore = New XmlStreamStore(stream)
service.Enable(store)
End If
End Sub
Protected Shadows Sub OnClosed(sender As Object, e As EventArgs)
' Disable and save annotations
Dim service As AnnotationService = AnnotationService.GetService(reader6)
If service IsNot Nothing AndAlso service.IsEnabled Then
service.Store.Flush()
service.Disable()
stream.Close()
End If
End Sub
End Class
The code was written for a tutorial to see Annotations in action with a Flow Document. The Window element on the XAML page has:
Initialized="OnInitialized" Closed="OnClosed"
Why is Shadow required instead of Overrides, and is this a proper use of Shadows? I've used Overrides before without problem, but not here. It seemed like some of the later comments in the referenced post may have been relevant to this situation and indicated Shadows is OK, but I wanted to ask this question pointedly.