WPF Docking Panes
Like WPF Window Layouts, WPF Docking Panes allow WPF layouts inside a MFC Feature Pack Docking Pane. In a WPF Docking Pane, you can add any kind of WPF control. Examples include the WPF Calendar and any of the WPF layout controls, such as Canvas.
Overrides
When creating a WPF control inside a Docking Pane, two functions should be overridden, CreateControl() and AdjustLayout().
CreateControl()
The function CreateControl() handles any special control creation that might be needed, such as custom sizes and control properties. A typical example of CreateControl() is:
 
BOOL CWPFDockingPane2::CreateControl()
{
if(m_wpfControlType)
{
try
{
// Create the WPF Control
m_wpfFrameworkElement =
safe_cast<Canvas^>(
Activator::CreateInstance(m_wpfControlType) );
if(m_wpfFrameworkElement)
{
CRect rect;
GetClientRect(&rect);
GetWpfControl()->Height = rect.Height();
//Add 1 to work around CTP bug
GetWpfControl()->Width =
rect.Width() + CPPCLI_CTP_WIDTH_OFFSET_BUG;
// Set the background to white so it looks
// more pleasing to the eye.
((Canvas^)(FrameworkElement^)m_wpfFrameworkElement)->
Background = Brushes::White;
 
}
}catch(NotSupportedException^ e)
{
Console::WriteLine("SFLWPFDockableCtrlPaneEx
Exception: {0}", e->Message);
return false;
}catch(Reflection::TargetInvocationException^ e)
{
Console::WriteLine("SFLWPFDockableCtrlPaneEx
Exception: {0}", e->Message);
return false;
}
 
}
return TRUE;
}
AdjustLayout()
The function AdjustLayout() handles any special layout considerations such as positioning of nested controls. A typical example of AdjustLayout() is:
 
void CWPFDockingPane2::AdjustLayout()
{
if(m_wpfFrameworkElement)
{
// Width and Height.
CRect rect;
GetClientRect(&rect);
GetWpfControl()->Height = rect.Height();
GetWpfControl()->Width = rect.Width() +
//Adding 1 to work around CTP bug
//CPPCLI_CTP_WIDTH_OFFSET_BUG;
((Canvas^)(FrameworkElement^)GetWpfControl())->
Background = Brushes::White;
}
}