I have this main wpf window

and this WPF page

I need to add this page to tabcontrol in the main window
This is my OnRender method
protected override void OnRender(DrawingContext drawingContext)
{
if (ISFirstRender)
{
TabItem tabitem = new TabItem();
tabitem.Header = "Tab 3";
pan1.Items.Add(tabitem);
Page1 page1 = new Page1();
tabitem.Content = new Page1();
ISFirstRender = false;
}
base.OnRender(drawingContext);
}
after starting the application, I encountered this exception when choosing a new tab


I need to know how to add a wpf page to an existing tabcontroll
source
share