WPF TabControl.Resources - 仅限样式一个选项卡

时间:2014-08-21 15:06:53

标签: c# wpf tabcontrol

我按如下方式定义TabControl:

<TabControl Name="TabsControl"
            ItemsSource="{Binding Tabs}"
            SelectedItem="{Binding SelectedTabViewModel}">

    <TabControl.Resources>

        <!-- Rate Tables Tab -->
        <DataTemplate DataType="{x:Type vm:RateTablesViewModel}">
            <v:RateTablesUserControl />
        </DataTemplate>

        <!-- Rate Tables Tab -->
        <DataTemplate DataType="{x:Type vm:RulesViewModel}">
            <v:RulesUserControl />

        </DataTemplate>

        <!-- Rate Tables Tab -->
        <DataTemplate DataType="{x:Type vm:CreateEmployeeMatchViewModel}">
            <v:CreateEmployeeMatchUserControl />
        </DataTemplate>

        <!-- Rate Tables Tab -->
        <DataTemplate DataType="{x:Type vm:ReportViewModel}">
            <v:ReportUserControl />
        </DataTemplate>

        <!-- System Setup Tab -->
        <DataTemplate DataType="{x:Type vm:SystemSetupViewModel}">
            <v:SystemSetupUserControl />
        </DataTemplate>

    </TabControl.Resources>


    <TabControl.ItemContainerStyle>
        <Style TargetType="TabItem">
            <Setter Property="Header" Value="{Binding Header}" />
        </Style>
    </TabControl.ItemContainerStyle>

</TabControl>

在我的词典中,我有以下风格:

<!-- Style for showing/hiding Setup tab -->
<Style x:Key="SetupTabStyle" TargetType="{x:Type TabItem}">
    <Setter Property="Visibility" Value="Collapsed" />
    <Style.Triggers>
        <DataTrigger Binding="{Binding RelativeSource={RelativeSource FindAncestor, 
                               AncestorType={x:Type Window}}, Path=DataContext.StartArg}" Value="Setup">
            <Setter Property="Visibility" Value="Visible" />
        </DataTrigger>
        <DataTrigger Binding="{Binding RelativeSource={RelativeSource FindAncestor, 
                               AncestorType={x:Type Window}}, Path=DataContext.StartArg}" Value="Edit">
            <Setter Property="Visibility" Value="Visible" />
        </DataTrigger>
    </Style.Triggers>
</Style>

如何将此样式仅应用于SystemSetup选项卡?

0 个答案:

没有答案