Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将TabItem样式更改为TabControl.ItemTemplate_C#_Wpf_Xaml - Fatal编程技术网

C# 将TabItem样式更改为TabControl.ItemTemplate

C# 将TabItem样式更改为TabControl.ItemTemplate,c#,wpf,xaml,C#,Wpf,Xaml,谁能帮帮我吗。 我已经为TabItem标题编写了样式。 但是因为我的TabItem标题是绑定的,所以我需要使用 TabControl.ItemTemplate而不是TabItem标头 那么,如何在TabControl.ItemTemplate上获得与TabItem相同的样式呢 所以我有这个: <TabItem Header="Tab1" Style="{StaticResource TabStyle}"> </TabItem> 现在我有这个: <TabCont

谁能帮帮我吗。 我已经为TabItem标题编写了样式。 但是因为我的TabItem标题是绑定的,所以我需要使用 TabControl.ItemTemplate而不是TabItem标头

那么,如何在TabControl.ItemTemplate上获得与TabItem相同的样式呢

所以我有这个:

<TabItem Header="Tab1" Style="{StaticResource TabStyle}">
</TabItem>

现在我有这个:

<TabControl.ItemTemplate>
  <!-- this is the header template-->
  <DataTemplate>
     <TextBlock Text="{Binding Person}" />
  </DataTemplate>
</TabControl.ItemTemplate>

这是原始选项卡项的样式:

<Style x:Key="TabStyle" TargetType="{x:Type TabItem}">
    <Setter Property="Background" Value="Transparent"/>
    <Setter Property="VerticalContentAlignment" Value="Center"/>
    <Setter Property="HorizontalContentAlignment" Value="Center"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type TabItem}">
                <Border  Padding="3">
                    <Grid Name ="grid" Height="24">
                        <Border Name="BorderName" 
                                CornerRadius="12,12,12,12"                           
                                Background="{TemplateBinding Background}" 
                                BorderBrush="{TemplateBinding BorderBrush}" 
                                BorderThickness="{TemplateBinding BorderThickness}"     />
                        <Rectangle Name="TabItemBackgorund" 
                                RadiusX="12"
                                RadiusY="12" 
                                Fill="{StaticResource TabItemBackgroundBrush}">
                        </Rectangle>
                        <Border Name="border" 
                                BorderThickness="{TemplateBinding BorderThickness}" 
                                Padding="{TemplateBinding Padding}">
                            <ContentPresenter Name="TabItemTextbox" 
                                ContentSource="Header" 
                                Margin="6,0,6,0"     
                                TextBlock.Foreground="{StaticResource TabItemBackgroundBrush}"
                                HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
                                VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
                        </Border>
                    </Grid>
                </Border>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsSelected" Value="True">
                        <Setter TargetName="TabItemBackgorund" Property="Fill"  Value="#00bfc2" />
                        <Setter TargetName="TabItemTextbox" Property="TextBlock.Foreground"  Value="#ffffff" />
                        <Setter TargetName="TabItemTextbox" Property="TextBlock.FontWeight"  Value="Bold" />
                    </Trigger>
                    <Trigger Property="IsSelected" Value="False">
                        <Setter TargetName="TabItemBackgorund" Property="Fill"  Value="{StaticResource TabItemBackgroundBrush}" />
                        <Setter TargetName="TabItemTextbox" Property="TextBlock.Foreground"  Value="#9494a3" />
                        <Setter TargetName="TabItemTextbox" Property="TextBlock.FontWeight"  Value="Bold" />
                    </Trigger>
                    <Trigger Property="IsEnabled" Value="False">
                        <Setter TargetName="TabItemBackgorund" Property="Fill"  Value="#00bfc2" />
                        <Setter TargetName="TabItemTextbox" Property="TextBlock.Foreground"  Value="#ffffff" />
                        <Setter TargetName="TabItemTextbox" Property="TextBlock.FontWeight"  Value="Bold" />
                    </Trigger>
                    <Trigger SourceName="grid" Property="IsMouseOver" Value="True">
                        <Setter TargetName="TabItemBackgorund" Property="Fill"  Value="#FF4F78" />
                        <Setter TargetName="TabItemTextbox" Property="TextBlock.Foreground"  Value="#ffffff" />
                        <Setter TargetName="TabItemTextbox" Property="TextBlock.FontWeight"  Value="Bold" />
                    </Trigger>

                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

我已经为TabItem标题编写了样式。但是因为我的 TabItem标题已绑定我需要使用TabControl.ItemTemplate 而不是TabItem标题

您可以继续使用带有
标题的
Setter

<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="Header" Value="{Binding Person}"/>
<Setter Property="Template">


我已经为TabItem标题编写了样式。但是因为我的 TabItem标题已绑定我需要使用TabControl.ItemTemplate 而不是TabItem标题

您可以继续使用带有
标题的
Setter

<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="Header" Value="{Binding Person}"/>
<Setter Property="Template">



非常感谢您。这正是我所需要的,最后一个问题:如何在资源中使用这种样式?我已经试过了,但是得到的消息不能是空的?直接将
ItemContainerStyle
绑定到
TabControl
中的资源,就像
非常感谢。这正是我所需要的,最后一个问题:如何在资源中使用这种样式?我已尝试过此操作,但获取的消息不能为空?直接将
ItemContainerStyle
绑定到
TabControl
中的资源,如

        </Style>
    </TabControl.ItemContainerStyle>
</TabControl>