I am trying to add dynamic tabs to my application. Right now if I click a button, it will open a new page. What I want is to open this page in a new tab. But when I set up the tab content to a page , the code complains. I wanna do something like this
private void bttnGoToClientsOnClick(object sender, RoutedEventArgs e)
{
var content = new TextBlock();
TabItem tab = new TabItem();
tab.Header = "Search Page";
SearchPage sp = new SearchPage();
tab.Content = sp;
tabControl.Items.Add(tab);
this.NavigationService.Navigate(sp);
}
is there any way I can convert my page to usercontrol or cast it as user control
Thank you!
It wouldn’t hurt if you were more specific here 🙂
What is
SearchPageclass? It doesn’t seem to be the part of the WPF framework. I googled it up on thehttp://www.intersoftpt.com/ website. Is that it?
TabItem.Contentneeds to be ofContentControltype, whichSearchPage– apparently – is not. I’m sure you need to embed thisSearchPageobject in some control presenter, such as a panel, before you can assign it toTabItem.Content.Update:
Try this, then:
While I believe this should work, I haven’t tested it. Please let me know if it doesn’t do the trick.