【问题标题】:Set Dynamic generated TabItem´s style from App.xaml从 App.xaml 设置动态生成的 TabItem 样式
【发布时间】:2011-01-08 04:43:27
【问题描述】:

在我的应用程序中,我有一个由一些菜单和菜单项以及TabControl 组成的主窗口。在Window.DataContext 中,我引用了我的ViewModel,其中包含一个名为ItemsObservableCollection<MyItemModel> 类型的属性。

我的TabControl.ItemsSource 绑定到Items 属性,因此TabItems 被动态声明:

<Window>
...
<Window.DataContext>
<local:ViewModel x:Name="model" />
</Window.DataContext>

...

<TabControl ItemsSource="{Binding Items}" />

</Window>

现在我想在 App.xaml 中为我的TabItems 定义一个Style,如下所示:

<App.xaml>
...

<Style TargetType="{x:Type TabItem}" x:Key="MyTabItem">
...
</Style>

...
<App.xaml>

在我的Window 中使用这个Style。但问题是如果TabControl 没有ItemsStyle 或类似的属性怎么办?

【问题讨论】:

    标签: wpf styles tabcontrol tabitem


    【解决方案1】:

    你试过了吗

    <TabControl ItemsSource="{Binding Items}" 
                ItemContainerStyle="{StaticResource MyTabItem}/>"
    

    ?

    【讨论】:

    • 我也一直在努力寻找那个属性,它应该被命名为smth。不同的。例如 TabItemStyle。
    • @Vitalij 它的存在是有充分理由的。当你习惯了 ItemsControl 的 conecpt 之后,你一定会喜欢它的一致性。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-30
    • 1970-01-01
    相关资源
    最近更新 更多