バージョン

InitializePaneContent イベント

コンテンツ ペインがレイアウトで参照されるが XamDockManager 内に存在しない時に、LoadLayout(Stream) への呼び出しの間に発生します。
シンタックス
'宣言
 
Public Event InitializePaneContent As EventHandler(Of InitializePaneContentEventArgs)
public event EventHandler<InitializePaneContentEventArgs> InitializePaneContent
イベント データ

イベント ハンドラが、このイベントに関連するデータを含む、InitializePaneContentEventArgs 型の引数を受け取りました。次の InitializePaneContentEventArgs プロパティには、このイベントの固有の情報が記載されます。

プロパティ解説
Handled 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 Infragistics.Windows.DockManager.XamDockManager に現在存在しない、読み込み中のレイアウトのペインを表す新しい Infragistics.Windows.DockManager.ContentPane を取得または設定します。
OriginalSource 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 System.Windows.RoutedEventArgsから継承されます。Gets or sets the System.Windows.RoutedEventArgs.RoutedEvent associated with this System.Windows.RoutedEventArgs instance.
Source System.Windows.RoutedEventArgsから継承されます。Gets or sets a reference to the object that raised the event.
解説

InitializePaneContent イベントは、レイアウトが読み込みされている時に XamDockManager 内に存在しない ContentPane を参照するレイアウトが読み込みされると発生します。Infragistics.Windows.DockManager.Events.InitializePaneContentEventArgs.NewPaneSystem.Windows.Controls.ContentControl.Content プロパティの設定が必要です。設定されていない場合、ペインはレイアウトから削除されます。SerializationId を使用して、ペインのコンテンツを初期化する方法を決定するために使用される情報をレイアウトに保存することができます。たとえば、SerializationId は、レイアウトが保存された時に読み込みされたファイル名に設定できます。

Infragistics.Windows.DockManager.Events.InitializePaneContentEventArgs.NewPane を新しい ContentPane に設定することも可能です。新しいペインに設定された場合は、ペインは常にレイアウトで使用されます。

使用例
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;
}
参照