• WPF自定义TabItem样式


    <SolidColorBrush x:Key="TabItem.Static.Foreground" Color="#42445A" />
    <SolidColorBrush x:Key="TabItem.Selected.Foreground" Color="#0176FF" />
    
    <Style x:Key="TabItemStyle1" TargetType="{x:Type TabItem}">
    <Setter Property="FocusVisualStyle" Value="{x:Null}" />
    <Setter Property="Foreground" Value="Black" />
    <Setter Property="Background" Value="Transparent" />
    <Setter Property="BorderBrush" Value="Transparent" />
    <Setter Property="Margin" Value="0" />
    <Setter Property="Padding" Value="6,2,6,2" />
    <Setter Property="HorizontalContentAlignment" Value="Stretch" />
    <Setter Property="VerticalContentAlignment" Value="Stretch" />
    <Setter Property="Template">
    <Setter.Value>
    <ControlTemplate TargetType="{x:Type TabItem}">
    <Grid x:Name="templateRoot" SnapsToDevicePixels="true">
    <Border
    x:Name="mainBorder"
    Margin="0"
    Background="{TemplateBinding Background}"
    BorderBrush="{TemplateBinding Background}"
    BorderThickness="0" />
    <Grid
    x:Name="underLine"
    Height="2"
    Margin="3,0"
    VerticalAlignment="Bottom"
    Visibility="Collapsed" />
    <ContentPresenter
    x:Name="contentPresenter"
    Margin="{TemplateBinding Padding}"
    HorizontalAlignment="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"
    VerticalAlignment="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"
    ContentSource="Header"
    Focusable="False"
    RecognizesAccessKey="True"
    SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
    </Grid>
    <ControlTemplate.Triggers>
    <MultiDataTrigger>
    <MultiDataTrigger.Conditions>
    <Condition Binding="{Binding IsMouseOver, RelativeSource={RelativeSource Self}}" Value="true" />
    <Condition Binding="{Binding TabStripPlacement, RelativeSource={RelativeSource AncestorType={x:Type TabControl}}}" Value="Top" />
    </MultiDataTrigger.Conditions>
    <Setter TargetName="contentPresenter" Property="TextElement.Foreground" Value="{StaticResource TabItem.Selected.Foreground}" />
    <Setter TargetName="contentPresenter" Property="Opacity" Value="0.56" />
    </MultiDataTrigger>
    <MultiDataTrigger>
    <MultiDataTrigger.Conditions>
    <Condition Binding="{Binding IsSelected, RelativeSource={RelativeSource Self}}" Value="false" />
    <Condition Binding="{Binding TabStripPlacement, RelativeSource={RelativeSource AncestorType={x:Type TabControl}}}" Value="Top" />
    </MultiDataTrigger.Conditions>
    <Setter TargetName="underLine" Property="Visibility" Value="Collapsed" />
    <Setter TargetName="contentPresenter" Property="TextElement.Foreground" Value="{StaticResource TabItem.Static.Foreground}" />
    </MultiDataTrigger>
    <MultiDataTrigger>
    <MultiDataTrigger.Conditions>
    <Condition Binding="{Binding IsSelected, RelativeSource={RelativeSource Self}}" Value="true" />
    <Condition Binding="{Binding TabStripPlacement, RelativeSource={RelativeSource AncestorType={x:Type TabControl}}}" Value="Top" />
    </MultiDataTrigger.Conditions>
    <Setter TargetName="underLine" Property="Visibility" Value="Visible" />
    <Setter TargetName="underLine" Property="Background" Value="{StaticResource TabItem.Selected.Foreground}" />
    <Setter TargetName="contentPresenter" Property="TextElement.Foreground" Value="{StaticResource TabItem.Selected.Foreground}" />
    </MultiDataTrigger>
    </ControlTemplate.Triggers>
    </ControlTemplate>
    </Setter.Value>
    </Setter>
    </Style>
    

     

     显示效果如下:

  • 相关阅读:
    redis深度理解底层锁原理
    深度完整的了解MySQL锁
    今天的文章很不一般
    利用h5来进行定位当前位置
    workerman(环境+初识)
    Nginx(防止压力测试的恶意攻击)
    Java Web框架——自己动手实现一个简化版的Spring IOC框架
    设计模式——策略模式
    数据库——深入理解MySQL事务
    缓存——Redis和Memcache的对比
  • 原文地址:https://www.cnblogs.com/wangjinming/p/15093617.html
Copyright © 2020-2023  润新知