我有一个TabControl和一些TabItems。每个TabItem都有一个具有TextBlock和一个图像的网格,其中包含透明的区域。
我的目标是使文本和图像完全可见,并通过透明区域看到Window.Background图像。
问题:无论我尝试了什么,我设置的图像和TextBlock背后都有一个白色的背景。
我试图将TabControl不透明设置为0,但这使整个事情不透明,正如预期的那样。TabItem不透明-> TabItem的结果是不可见的。接下来,我将TabItems前台、BorderBrush和背景设置为Opacity="0“--什么都不改变:(
我对WPF比较陌生,英语不是我的母语,所以如果我的问题很笨,我的英语很差,请原谅我。
提前感谢!
编辑(屏幕链接):http://i.stack.imgur.com/NN8AR.png
我不能张贴截图,因为我没有10个声誉,所以我增加了链接到它。
I removed the images and only left the Textboxes so there is no confusion about that
发布于 2014-12-03 16:34:45
要做到这一点,您需要定制一个TabItem ControlTemplate。
下面是一个稍微修改过的TabItem ControlTemplate (从默认设置稍微修改一下)
<SolidColorBrush x:Key="SolidBorderBrush" Color="#888" />
<SolidColorBrush x:Key="DisabledBorderBrush" Color="#AAA" />
<SolidColorBrush x:Key="DisabledForegroundBrush" Color="#888" />
<Style TargetType="{x:Type TabItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TabItem}">
<Grid Background="Transparent">
<Border
Name="Border"
Margin="0,0,-4,0"
Background="Transparent"
BorderBrush="{StaticResource SolidBorderBrush}"
BorderThickness="1,1,1,1"
CornerRadius="2,12,0,0" >
<ContentPresenter x:Name="ContentSite"
VerticalAlignment="Center"
HorizontalAlignment="Center"
ContentSource="Header"
Margin="12,2,12,2"
RecognizesAccessKey="True"/>
</Border>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Panel.ZIndex" Value="100" />
<Setter TargetName="Border" Property="BorderThickness" Value="1,1,1,0" />
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource DisabledBorderBrush}" />
<Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
您可能需要修改它,以显示选择了什么TabItem (在IsSelected上的触发器中)。
https://stackoverflow.com/questions/27269217
复制相似问题