动态地将样式分配给 TabItem 控件

发布于 2024-07-08 06:09:22 字数 255 浏览 8 评论 0原文

我在 App.xaml 文件“tabControlStyle”中定义了一个样式。 如何将此样式分配给动态创建的 TabItem 控件。

 TabItem item = new TabItem();               



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

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);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

奢华的一滴泪 2024-07-15 06:09:22

我得到了答案。 这里是:

 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);
            }
        }

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);
            }
        }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文