Search code examples
c#wpfevent-handlingtabitem

WPF - creating content for a tabitem dynamically


I'd like to set the content of a tabitem dynamically, based on the content/actions taken on previous tabitems.

I'm advancing through the tabs via a command like:

tabControl1.SelectedIndex++;

However, the Loaded event doesn't get fired after this like I thought it would. tabControl1_SelectionChanged() is getting called, however. Should I manually call the tabitem's Load() event from SelectionChanged(), or is there a better way of doing this?


Solution

  • Load will get called only once for every TabItem. but you can get the required TabItem instance from the SelectionChanged and set its content