web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Blogs / Nishant Rana’s Weblog / Creating dynamic TabItem in...

Creating dynamic TabItem in WPF.

Nishant Rana Profile Picture Nishant Rana 11,325 Microsoft Employee

Hi,

We recently had a requirement in our project to create dynamic TabItems

something similar to below screen shot.

Here every time when we click on Add View One and Add View Two buttons a new TabItem gets added to the tab control on the right side showing its respective views.

The project structure is like this

Two views, ViewTypeOne and ViewTypeTwo with a simple textblock in them.

Two ViewModel for those views, one for the main window and the fourth one VMParentForView which is the parent of our other two view models.

VMParentForView class

The TabControl in the main window is bind to the ObservableCollection of VMParentForViews viewmodel and the Textblock to the Header property of Views.


<TabControl Height=”271″ HorizontalAlignment=”Left” Margin=”123,9,0,0″ Name=”mainTabControl” VerticalAlignment=”Top” Width=”441″ 
IsSynchronizedWithCurrentItem=”True” ItemsSource=”{Binding ObservableCollectionTabItems}” Background=”White”>

<TabControl.ItemTemplate>

<DataTemplate>

<TextBlock Text=”{Binding Header}” ></TextBlock>

</DataTemplate>

</TabControl.ItemTemplate>

</TabControl>

Here is the sample code of the demo application.

https://skydrive.live.com/redir.aspx?cid=2312e1103cbe5ecd&resid=2312E1103CBE5ECD!337&parid=root

Hope it helps.


Filed under: WPF Tagged: WPF

This was originally posted here.

Comments

*This post is locked for comments