我有困難的所有方式與下面的代碼,直到我引用這個SO post並決定我必須需要陰影,在這之後的工作就好了;我只是不太明白這一點。引用的帖子似乎有很多信徒對'不喜歡使用陰影'組,但我不明白如何在沒有陰影的情況下編寫下面的代碼,我也不明白爲什麼最終需要它。爲什麼此代碼需要陰影而不是覆蓋?
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
該代碼是爲教程編寫的,以查看使用流文檔操作的註釋。 XAML頁面上的Window元素有:
Initialized="OnInitialized" Closed="OnClosed"
爲什麼需要Shadow而不是Overrides,這是否正確使用了Shadows?我之前使用Overrides沒有問題,但沒有在這裏。這篇文章後面的一些評論看起來似乎與這種情況有關,並指出Shadows是可以的,但我想指出這個問題。
這是因爲基類方法不可用,因此您爲什麼需要使用'shadows' ......使用'shadows'保留和/或維護方法'OnClosed'的定義;原因是如果基類方法已被更改。 – Codexer