tags:

views:

344

answers:

1

Hi,

I have a style defined in App.xaml file "tabControlStyle". How can I assign this style to my dynamically created TabItem control.

 TabItem item = new TabItem();               



                item.Header = String.Format("Item {0}", i);
                documentTab.Items.Add(item);
+1  A: 

I got the answer. Here it is:

 private void PopulateTabControl()
        {
            for(int i=1; i<=10;i++)
            {
                TabItem item = new TabItem();
                item.Style = Application.Current.Resources["tabItemStyle"] as Style;
                item.Header = String.Format("Item {0}", i);
                documentTab.Items.Add(item);
            }
        }
azamsharp