Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在 App.xaml 文件“tabControlStyle”中定义了一个样式。如何将此样式分配给我动态创建的 TabItem 控件。
TabItem item = new TabItem(); item.Header = String.Format("Item {0}", i); documentTab.Items.Add(item);
我得到了答案。这里是:
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); } }