私はこのSO postを参照してシャドーが必要であると判断するまで、私は以下のコードですべての難しさを持っていました。私はそれを本当に理解していない。参照された投稿には、Shadowsのグループを使用するのが好きではありませんでしたが、以下のコードがShadowsなしでどのように書かれているのか、私は最終的になぜ必要なのか理解できません。このコードでは、[上書き]ではなく[影]が必要なのはなぜですか?
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ページ上のウィンドウの要素があります。
Initialized="OnInitialized" Closed="OnClosed"
なぜシャドウはオーバーライドするのではなく、必要に応じ、これは影の適切な使用ですか?以前は、問題なしに上書きを使用しましたが、ここでは使用しません。参照された投稿の後のコメントのいくつかがこの状況に関連し、ShadowsがOKであることが示されているように思えましたが、私はこの質問を慎重に尋ねたかったのです。
これは、基本クラスのメソッドが利用できないため、なぜあなたは 'shadows'を使用する必要があるのでしょうか?' shadows'を使用すると、 'OnClosed'メソッドの定義が維持または維持されます。その理由は、基本クラスのメソッドが変更された場合です。 – Codexer