Version

InitializePaneContent Event

Occurs during a call to LoadLayout(Stream) when a content pane is referenced in the layout but does not exist within the XamDockManager.
Syntax
'Declaration
 
Public Event InitializePaneContent As EventHandler(Of InitializePaneContentEventArgs)
public event EventHandler<InitializePaneContentEventArgs> InitializePaneContent
Event Data

The event handler receives an argument of type InitializePaneContentEventArgs containing data related to this event. The following InitializePaneContentEventArgs properties provide information specific to this event.

PropertyDescription
Handled (Inherited from System.Windows.RoutedEventArgs)Gets or sets a value that indicates the present state of the event handling for a routed event as it travels the route.
NewPane Returns or sets the new Infragistics.Windows.DockManager.ContentPane representing a pane in the layout being loaded that does not currently exist within the Infragistics.Windows.DockManager.XamDockManager.
OriginalSource (Inherited from System.Windows.RoutedEventArgs)Gets the original reporting source as determined by pure hit testing, before any possible System.Windows.RoutedEventArgs.Source adjustment by a parent class.
RoutedEvent (Inherited from System.Windows.RoutedEventArgs)Gets or sets the System.Windows.RoutedEventArgs.RoutedEvent associated with this System.Windows.RoutedEventArgs instance.
Source (Inherited from System.Windows.RoutedEventArgs)Gets or sets a reference to the object that raised the event.
Remarks

The InitializePaneContent event is raised when a layout is loaded that references a ContentPane that does not exist within the XamDockManager when the layout is being loaded. The System.Windows.Controls.ContentControl.Content property of the Infragistics.Windows.DockManager.Events.InitializePaneContentEventArgs.NewPane must be set. If it is not set then the pane will be removed from the layout. The SerializationId may be used to store information in the layout that may be used to determine how to initialize the content of the pane. For example, the SerializationId could be set to the name of the file that was loaded when the layout was saved.

The Infragistics.Windows.DockManager.Events.InitializePaneContentEventArgs.NewPane may also be set to a new ContentPane. If set to a new pane, the pane will always be used in the layout.

Example
This example uses the InitializePaneContent event to recreate the content for a dynamically created ContentPane based upon a value stored in its SerializationId.

For an overview of how to handle events in Visual Basic or Visual C#, see Event Handlers in Visual Basic and Visual C#. For specific information and code examples illustrating how to consume events in your application, see Consuming Events in the .NET Framework Developer's Guide.

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
using Infragistics.Windows.DockManager;
using Infragistics.Windows.DockManager.Events;

private void InitializeDmWithSaveInLayout(XamDockManager dockManager)
{
	// 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
	dockManager.InitializePaneContent += new EventHandler<InitializePaneContentEventArgs>(dockManager_InitializePaneContent);
}

private void mnuOpen_Click(object sender, RoutedEventArgs e)
{
	string file = this.OpenFile();
	RichTextBox rtb = CreateRichTextBox(file, DataFormats.Rtf);

	if (null != rtb)
	{
		string fileName = System.IO.Path.GetFileName(file);
		ContentPane cp = this.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;
	}
}

private void dockManager_InitializePaneContent(object sender, InitializePaneContentEventArgs e)
{
	string id = e.NewPane.SerializationId;

	RichTextBox rtb = 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;
}

// simple helper method for prompting for an rtf file
private string OpenFile()
{
	// you could show a file open dialog, etc.
	Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
	dlg.DefaultExt = ".rtf";
	dlg.Filter = "RichText Files (*.rtf)|*.rtf";

	if (dlg.ShowDialog(this) == true)
		return dlg.FileName;

	return null;
}

// simple helper method for creating a richtextbox with
// contents loaded from a specified file
private static RichTextBox CreateRichTextBox(string fileName, string format)
{
	if (System.IO.File.Exists(fileName))
	{
		RichTextBox rtb = new RichTextBox();
		TextRange range = new TextRange(rtb.Document.ContentStart, rtb.Document.ContentEnd);

		using (System.IO.FileStream stream = 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);
		}

		return rtb;
	}

	return null;
}
Requirements

Target Platforms: Windows 10, Windows 8.1, Windows 8, Windows 7, Windows Server 2012, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also