Imports Infragistics.Windows.DockManager
Imports Infragistics.Windows.DockManager.Events
Private Sub InitializeDmWithSaveInLayout(ByVal dockManager As XamDockManager)
' hook the InitializePaneContent to dynamically provide the
' content for panes that are loaded at runtime. for example,
' if your application creates documents for files that the
' user opens you could let those panes be saved, store information
' in the SerializationId of the pane to know what to load and then
' load that information into the pane in the InitializePaneContent
' when you load a layout
AddHandler dockManager.InitializePaneContent, AddressOf dockManager_InitializePaneContent
End Sub
Private Sub mnuOpen_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
Dim file As String = Me.OpenFile()
Dim rtb As RichTextBox = CreateRichTextBox(file, DataFormats.Rtf)
If rtb IsNot Nothing Then
Dim fileName As String = System.IO.Path.GetFileName(file)
Dim cp As ContentPane = Me.dmSaveInLayout.AddDocument(fileName, rtb)
' in order for the pane to be saved we must give it a unique name
' since we won't be using the name we can just use a guid. we have
' to use the format string that does not include "-" since that
' is not valid for an element name. prefix with a letter since
' the name cannot start with a number
cp.Name = "A" + Guid.NewGuid().ToString("N")
' store the path to the file. the SerializationId will be saved
' in the layout with the pane so we can use this information from
' within the InitializePaneContent to know what file to load
' when a layout containing this pane is loaded
cp.SerializationId = file
End If
End Sub
Private Sub dockManager_InitializePaneContent(ByVal sender As Object, ByVal e As InitializePaneContentEventArgs)
Dim id As String = e.NewPane.SerializationId
Dim rtb As RichTextBox = CreateRichTextBox(id, DataFormats.Rtf)
' if you set the Content of the NewPane to a non-null value then that
' pane will be kept in the newly loaded layout. if you do not set the
' content to a non-null value then the pane will be discarded
e.NewPane.Content = rtb
End Sub
Private Function OpenFile() As String
' simple helper method for prompting for an rtf file
' you could show a file open dialog, etc.
Dim dlg As New Microsoft.Win32.OpenFileDialog()
dlg.DefaultExt = ".rtf"
dlg.Filter = "RichText Files (*.rtf)|*.rtf"
If dlg.ShowDialog(Me) = True Then
Return dlg.FileName
End If
Return Nothing
End Function
' simple helper method for creating a richtextbox with
' contents loaded from a specified file
Private Shared Function CreateRichTextBox(ByVal fileName As String, ByVal format As String) As RichTextBox
If System.IO.File.Exists(fileName) Then
Dim rtb As New RichTextBox()
Dim range As New TextRange(rtb.Document.ContentStart, rtb.Document.ContentEnd)
Using stream As New System.IO.FileStream(fileName, System.IO.FileMode.Open)
' we're assuming that the serialization id you stored was the name of
' an rtf file
range.Load(stream, DataFormats.Rtf)
End Using
Return rtb
End If
Return Nothing
End Function