开发者论坛

 找回密码
 注册 (请使用非IE浏览器)
查看: 2626|回复: 0

请教一个关于wpf tabcontrol关闭按钮的解决方案

[复制链接]

0

精华

0

贡献

0

赞扬

帖子
14
软币
156
在线时间
13 小时
注册时间
2015-5-10
发表于 2015-12-15 15:12:07 | 显示全部楼层 |阅读模式
修改的Tabcontrol控件样式,有关闭按钮,没有后台关闭代码,请指导!
    <SolidColorBrush x:Key="BackgroundHighlighted" Color="#54545C" />
    <SolidColorBrush x:Key="BorderBrushHighlighted" Color="#6A6A75" />
    <SolidColorBrush x:Key="BackgroundSelected" Color="#FF007ACC" />
    <SolidColorBrush x:Key="BorderBrushSelected" Color="#1C97EA" />
    <SolidColorBrush x:Key="BackgroundNormal" Color="#3F3F46" />
    <SolidColorBrush x:Key="BorderBrushNormal" Color="#54545C" />
    <SolidColorBrush x:Key="CloseButtonBackgroundHighlighted" Color="#39ADFB" />
    <SolidColorBrush x:Key="CloseButtonBackgroundPressed" Color="#084E7D" />
    <SolidColorBrush x:Key="CloseButtonStroke" Color="#AAFFFFFF" />
    <SolidColorBrush x:Key="CloseButtonStrokeHighlighted" Color="#FFFFFF" />
    <Style x:Key="TabControlStyle"
           TargetType="{x:Type TabControl}">
        <Style.Resources>
            <Style TargetType="{x:Type TabItem}">
                <Setter Property="FocusVisualStyle"
                        Value="{x:Null}" />
                <Setter Property="Background"
                        Value="Transparent" />
                <Setter Property="Foreground"
                        Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" />
                <Setter Property="BorderThickness"
                        Value="0" />
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type TabItem}">
                            <Grid Height="30"
                                  Background="{TemplateBinding Background}"
                                  SnapsToDevicePixels="true">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="25" />
                                </Grid.ColumnDefinitions>
                                <ContentPresenter Grid.Column="0"
                                                  Margin="10,0,10,0"
                                                  HorizontalAlignment="Center"
                                                  VerticalAlignment="Center"
                                                  ContentSource="Header" />
                                <Button Grid.Column="1"
                                        Width="15"
                                        Height="15"
                                        HorizontalAlignment="Center"
                                        VerticalAlignment="Center"
                                        Command="{Binding Path=CloseCommand}"
                                        DockPanel.Dock="Right">
                                    <Button.Style>
                                        <Style TargetType="{x:Type Button}">
                                            <Setter Property="Background"
                                                    Value="Transparent" />
                                            <Setter Property="Cursor"
                                                    Value="Hand" />
                                            <Setter Property="Focusable"
                                                    Value="False" />
                                            <Setter Property="Template">
                                                <Setter.Value>
                                                    <ControlTemplate TargetType="{x:Type Button}">
                                                        <Grid Background="{TemplateBinding Background}">
                                                            <Path x:Name="ButtonPath"
                                                                  Margin="2"
                                                                  HorizontalAlignment="Center"
                                                                  VerticalAlignment="Center"
                                                                  Data="M0,0 L1,1 M0,1 L1,0"
                                                                  Stretch="Uniform"
                                                                  Stroke="{DynamicResource CloseButtonStroke}"
                                                                  StrokeEndLineCap="Flat"
                                                                  StrokeStartLineCap="Flat"
                                                                  StrokeThickness="2" />
                                                        </Grid>
                                                        <ControlTemplate.Triggers>
                                                            <MultiDataTrigger>
                                                                <MultiDataTrigger.Conditions>
                                                                    <Condition Binding="{Binding IsSelected, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=TabItem}}"
                                                                               Value="false" />
                                                                    <Condition Binding="{Binding IsMouseOver, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=TabItem}}"
                                                                               Value="false" />
                                                                </MultiDataTrigger.Conditions>
                                                                <MultiDataTrigger.Setters>
                                                                    <Setter Property="Visibility"
                                                                            Value="Hidden" />
                                                                </MultiDataTrigger.Setters>
                                                            </MultiDataTrigger>
                                                            <Trigger Property="IsEnabled"
                                                                     Value="False">
                                                                <Setter Property="Visibility"
                                                                        Value="Hidden" />
                                                            </Trigger>
                                                            <Trigger Property="IsMouseOver"
                                                                     Value="True">
                                                                <Setter Property="Background"
                                                                        Value="{DynamicResource CloseButtonBackgroundHighlighted}" />
                                                                <Setter TargetName="ButtonPath"
                                                                        Property="Stroke"
                                                                        Value="{DynamicResource CloseButtonStrokeHighlighted}" />
                                                            </Trigger>
                                                            <Trigger Property="IsPressed"
                                                                     Value="true">
                                                                <Setter Property="Background"
                                                                        Value="{DynamicResource CloseButtonBackgroundPressed}" />
                                                                <Setter TargetName="ButtonPath"
                                                                        Property="Stroke"
                                                                        Value="{DynamicResource CloseButtonStroke}" />
                                                                <Setter TargetName="ButtonPath"
                                                                        Property="Margin"
                                                                        Value="2.5,2.5,1.5,1.5" />
                                                            </Trigger>
                                                        </ControlTemplate.Triggers>
                                                    </ControlTemplate>
                                                </Setter.Value>
                                            </Setter>
                                        </Style>
                                    </Button.Style>
                                </Button>
                            </Grid>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsSelected"
                                         Value="false">
                                    <Setter Property="Background"
                                            Value="Transparent" />
                                </Trigger>
                                <Trigger Property="IsMouseOver"
                                         Value="true">
                                    <Setter Property="Background"
                                            Value="{DynamicResource BorderBrushSelected}" />
                                </Trigger>
                                <Trigger Property="IsSelected"
                                         Value="true">
                                    <Setter Property="Background"
                                            Value="{DynamicResource BackgroundSelected}" />
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </Style.Resources>
    </Style>
回复

使用道具 举报

Archiver|手机版|小黑屋|开发者网 ( 苏ICP备08004430号-2 )
版权所有:南京韵文教育信息咨询有限公司

GMT+8, 2024-4-19 21:30

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表