I have a dockinghost and a separate split container docked ot the right. I am trying to programmatically add panes and documentpanes with a user control. When I try to add a pane or document pane to the panegroup in the documenthost, I get an error:
NullReferenceException was unhandled by user code
Object reference not set to an instance of an object.
XAML and codebehind are below, any ideas why I get the error?
<telerik:RadDocking x:Name="ctlDocking">
<telerik:RadDocking.DocumentHost>
<telerik:RadSplitContainer>
<telerik:RadPaneGroup x:Name="TopPaneGroup">
</telerik:RadPaneGroup>
</telerik:RadSplitContainer>
</telerik:RadDocking.DocumentHost>
<telerik:RadSplitContainer Orientation="Vertical" InitialPosition="DockedRight">
<telerik:RadPaneGroup x:Name="RightPaneGroup">
</telerik:RadPaneGroup>
</telerik:RadSplitContainer>
</telerik:RadDocking>
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
// this line works
AddPane("Issues", new UserControl(), "RightPaneGroup", DockPosition.Top);
// this line doesnt
AddDocumentPane("Issues", new UserControl(), "TopPaneGroup", DockPosition.Top);
}
private object FindPaneByTitle(string title)
{
return new object();
}
private RadPane AddPane(string title, UserControl control, string paneGroup, DockPosition position)
{
RadPaneGroup group = FindName(paneGroup) as RadPaneGroup;
RadPane r=null;
if (group != null)
{
r = new RadPane();
r.Title = title;
r.Content = control;
r.CanDockInDocumentHost = true;
group.AddItem(r, position);
}
return r;
}
private RadDocumentPane AddDocumentPane(string title, UserControl control, string paneGroup, DockPosition position)
{
RadPaneGroup group = FindName(paneGroup) as RadPaneGroup;
RadDocumentPane r=null;
if (group != null)
{
r = new RadDocumentPane();
r.Title = title;
r.Content = control;
r.CanDockInDocumentHost = true;
group.AddItem(r, position);
}
return r;
}
}