Search code examples
wpfuser-controlstabitem

Get WPF TabItem container from UserControl


I am setting the content of a UserControl, SIASystemTab, to a TabItem, ConfigTab. How do you access the TabItem from the UserControl using code behind? I would like to reuse the methods in the TabItem from multiple UserControls.

var subSystem = new SIASystemTab(opCo);
var configTab = new ConfigTab()
{
    Header = "New Header*",
    Content = subSystem
};

Solution

  • One simple way is to create a property in SIASystemTab like this

        public ConfigTab myConfigTab {get; set;}
    

    Then assign the ConfigTab instance to this property

       subSystem.myConfigTab = configTab;
    

    Later on u can use this as per your need