当前位置:网站首页 / WPF / 正文

AyTabControlBase样式分享

时间:2015年03月27日 | 作者 : aaronyang | 分类 : WPF | 浏览: 6768次 | 评论 1

 <Window.Resources>
        <sys:Double x:Key="TabItemShadowRadius">6</sys:Double>
        <Color x:Key="AyTabItem.Static.Shadow.Color1">#7F000000</Color>
        <Color x:Key="AyTabItem.Static.Shadow.Color2">#00000000</Color>
        <SolidColorBrush x:Key="TabItemShadowColor" Color="#E5404040"/>
        <Style x:Key="AyTabControl" TargetType="{x:Type TabControl}">
            <Setter Property="Padding" Value="4"/>
            <Setter Property="HorizontalContentAlignment" Value="Center"/>
            <Setter Property="VerticalContentAlignment" Value="Center"/>
            <Setter Property="Background" Value="White"/>
            <Setter Property="BorderBrush" Value="#FFACACAC"/>
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type TabControl}">
                     
                 
                      <Grid x:Name="templateRoot" ClipToBounds="True" SnapsToDevicePixels="True" KeyboardNavigation.TabNavigation="Local">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition x:Name="ColumnDefinition0"/>
                                    <ColumnDefinition x:Name="ColumnDefinition1" Width="0"/>
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition x:Name="RowDefinition0" Height="Auto"/>
                                    <RowDefinition x:Name="RowDefinition1" Height="*"/>
                                </Grid.RowDefinitions>

                                <TabPanel x:Name="HeaderPanel" Background="Transparent" Grid.Column="0" IsItemsHost="True" Margin="2,2,2,0" Grid.Row="0" KeyboardNavigation.TabIndex="1" Panel.ZIndex="1"/>


                            <Border  Grid.Column="0" x:Name="ContentPanel" Grid.Row="1" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}"  KeyboardNavigation.DirectionalNavigation="Contained"  KeyboardNavigation.TabIndex="2" KeyboardNavigation.TabNavigation="Local">
                                <Border.Effect>
                                    <DropShadowEffect ShadowDepth="1" Direction="340" BlurRadius="6" Color="#FF818181"/>
                                </Border.Effect>
                                <ContentPresenter x:Name="PART_SelectedContentHost" ContentTemplate="{TemplateBinding SelectedContentTemplate}" Content="{TemplateBinding SelectedContent}" ContentStringFormat="{TemplateBinding SelectedContentStringFormat}" ContentSource="SelectedContent" Margin="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                            </Border>
                           
                        </Grid>
                       
                        <ControlTemplate.Triggers>
                            <Trigger Property="TabStripPlacement" Value="Bottom">
                                <Setter Property="Grid.Row" TargetName="HeaderPanel" Value="1"/>
                                <Setter Property="Grid.Row" TargetName="ContentPanel" Value="0"/>
                                <Setter Property="Height" TargetName="RowDefinition0" Value="*"/>
                                <Setter Property="Height" TargetName="RowDefinition1" Value="Auto"/>
                                <Setter Property="Margin" TargetName="HeaderPanel" Value="2,0,2,2"/>
                            </Trigger>
                            <Trigger Property="TabStripPlacement" Value="Left">
                                <Setter Property="Grid.Row" TargetName="HeaderPanel" Value="0"/>
                                <Setter Property="Grid.Row" TargetName="ContentPanel" Value="0"/>
                                <Setter Property="Grid.Column" TargetName="HeaderPanel" Value="0"/>
                                <Setter Property="Grid.Column" TargetName="ContentPanel" Value="1"/>
                                <Setter Property="Width" TargetName="ColumnDefinition0" Value="Auto"/>
                                <Setter Property="Width" TargetName="ColumnDefinition1" Value="*"/>
                                <Setter Property="Height" TargetName="RowDefinition0" Value="*"/>
                                <Setter Property="Height" TargetName="RowDefinition1" Value="0"/>
                                <Setter Property="Margin" TargetName="HeaderPanel" Value="2,2,0,2"/>
                            </Trigger>
                            <Trigger Property="TabStripPlacement" Value="Right">
                                <Setter Property="Grid.Row" TargetName="HeaderPanel" Value="0"/>
                                <Setter Property="Grid.Row" TargetName="ContentPanel" Value="0"/>
                                <Setter Property="Grid.Column" TargetName="HeaderPanel" Value="1"/>
                                <Setter Property="Grid.Column" TargetName="ContentPanel" Value="0"/>
                                <Setter Property="Width" TargetName="ColumnDefinition0" Value="*"/>
                                <Setter Property="Width" TargetName="ColumnDefinition1" Value="Auto"/>
                                <Setter Property="Height" TargetName="RowDefinition0" Value="*"/>
                                <Setter Property="Height" TargetName="RowDefinition1" Value="0"/>
                                <Setter Property="Margin" TargetName="HeaderPanel" Value="0,2,2,2"/>
                            </Trigger>
                            <Trigger Property="IsEnabled" Value="False">
                                <Setter Property="TextElement.Foreground" TargetName="templateRoot" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
     
       
        <Style TargetType="{x:Type TabItem}" BasedOn="{StaticResource {x:Type TabItem}}">
            <Setter Property="TextBlock.Foreground" Value="#2B2A50" />
            <Setter Property="TextBlock.FontSize" Value="12" />
            <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
            <Setter Property="SnapsToDevicePixels" Value="true"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type TabItem}">
                   
                            <Grid Margin="-3,0,0,0">
                                <Grid.RowDefinitions>
                                    <RowDefinition></RowDefinition>
                                    <RowDefinition></RowDefinition>
                                    <RowDefinition></RowDefinition>
                                </Grid.RowDefinitions>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition></ColumnDefinition>
                                    <ColumnDefinition></ColumnDefinition>
                                    <ColumnDefinition></ColumnDefinition>
                                </Grid.ColumnDefinitions>
                                <Rectangle Grid.Column="0"  Grid.Row="0" Fill="{StaticResource TabItemShadowColor}"  Width="{StaticResource TabItemShadowRadius}" Height="{StaticResource TabItemShadowRadius}">
                                    <Rectangle.OpacityMask>
                                        <RadialGradientBrush GradientOrigin="1.468,1.393" RadiusX="0.417" RadiusY="0.417" Center="0.983,0.98">
                                            <GradientStop Color="{StaticResource AyTabItem.Static.Shadow.Color1}" Offset="0.555"/>
                                            <GradientStop Color="#33000000" Offset="0.855"/>
                                            <GradientStop Color="#00000000" Offset="1"/>
                                        </RadialGradientBrush>
                                    </Rectangle.OpacityMask>
                                </Rectangle>
                                <Rectangle Grid.Column="2"  Grid.Row="0" Fill="{StaticResource TabItemShadowColor}"  Width="{StaticResource TabItemShadowRadius}" Height="{StaticResource TabItemShadowRadius}">
                                    <Rectangle.OpacityMask>
                                        <RadialGradientBrush GradientOrigin="-0.592,1.43" RadiusX="0.417" RadiusY="0.417" Center="0.22,0.82">
                                            <GradientStop Color="{StaticResource AyTabItem.Static.Shadow.Color1}" Offset="0.434"/>
                                            <GradientStop Color="{StaticResource AyTabItem.Static.Shadow.Color2}" Offset="0.879"/>
                                        </RadialGradientBrush>
                                    </Rectangle.OpacityMask>
                                </Rectangle>

                                <Rectangle Grid.Column="1"  Grid.Row="0"  Width="140" Height="{StaticResource TabItemShadowRadius}" Fill="{StaticResource TabItemShadowColor}">
                                    <Rectangle.OpacityMask>
                                        <LinearGradientBrush EndPoint="0.5,0" StartPoint="0.5,1">
                                            <GradientStop Color="{StaticResource AyTabItem.Static.Shadow.Color1}"/>
                                            <GradientStop Offset="1"/>
                                            <GradientStop Color="{StaticResource AyTabItem.Static.Shadow.Color2}" Offset="0.84"/>
                                            <GradientStop Color="#199B9B9B" Offset="0.34"/>
                                        </LinearGradientBrush>
                                    </Rectangle.OpacityMask>


                                </Rectangle>
                                <Rectangle Grid.Column="0" Grid.Row="1"   Width="{StaticResource TabItemShadowRadius}" Height="36" Fill="{StaticResource TabItemShadowColor}">
                                    <Rectangle.OpacityMask>
                                        <LinearGradientBrush EndPoint="0,0.5" StartPoint="1,0.5">
                                            <GradientStop Color="{StaticResource AyTabItem.Static.Shadow.Color1}"/>
                                            <GradientStop Offset="1"/>
                                            <GradientStop Color="{StaticResource AyTabItem.Static.Shadow.Color2}" Offset="0.54"/>
                                        </LinearGradientBrush>
                                    </Rectangle.OpacityMask>
                                </Rectangle>
                                <Rectangle Grid.Column="2" Grid.Row="1"  Width="{StaticResource TabItemShadowRadius}" Height="36" Fill="{StaticResource TabItemShadowColor}">
                                    <Rectangle.OpacityMask>
                                        <LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
                                            <GradientStop Color="{StaticResource AyTabItem.Static.Shadow.Color1}"/>
                                            <GradientStop Offset="1"/>
                                            <GradientStop Color="{StaticResource AyTabItem.Static.Shadow.Color2}" Offset="0.46"/>
                                        </LinearGradientBrush>
                                    </Rectangle.OpacityMask>
                                </Rectangle>
                                <Border CornerRadius="0,0,0,0" Grid.Row="1" Grid.Column="1" x:Name="tabItemBorder" Height="35" Background="#7FFFFFFF" Width="140"  >
                                    <ContentPresenter x:Name="contentPresenter" 
                                              ContentSource="Header"
                                              Focusable="False" 
                                              HorizontalAlignment="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" 
                                              Margin="{TemplateBinding Padding}" 
                                              RecognizesAccessKey="True" 
                                              SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" 
                                              VerticalAlignment="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}">
                                    </ContentPresenter>
                                </Border>

                            </Grid>
                        


                        <ControlTemplate.Triggers>
                            <Trigger Property="IsSelected" Value="True">
                                <Setter TargetName="tabItemBorder" Property="Background" Value="#FFFFFF" />
                                <Setter  Property="Panel.ZIndex" Value="100" />
                            </Trigger>
                            <Trigger Property="IsSelected" Value="false">
                                <Setter  Property="Panel.ZIndex" Value="-1" />
                            </Trigger>
                            <MultiTrigger>
                                <MultiTrigger.Conditions>
                                    <Condition Property="IsSelected" Value="false"></Condition>
                                    <Condition Property="IsMouseOver" Value="True"></Condition>
                                </MultiTrigger.Conditions>
                                <Setter TargetName="tabItemBorder" Property="Background" Value="#B2FFFFFF" />
                            </MultiTrigger>
                         
                            <Trigger Property="TabStripPlacement" Value="Left">
                                <Setter Property="LayoutTransform">
                                    <Setter.Value>
                                        <RotateTransform Angle="-90" />
                                    </Setter.Value>
                                </Setter>
                            </Trigger>

                            <Trigger Property="TabStripPlacement" Value="Right">
                                <Setter Property="LayoutTransform">
                                    <Setter.Value>
                                        <RotateTransform Angle="90" />
                                    </Setter.Value>
                                </Setter>
                            </Trigger>
                            <Trigger Property="TabStripPlacement" Value="Bottom">
                                <Setter Property="LayoutTransform">
                                    <Setter.Value>
                                        <RotateTransform Angle="180" />
                                    </Setter.Value>
                                </Setter>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>

        </Style>

    </Window.Resources>

使用方法:

<TabControl BorderThickness="1,0,1,1"  HorizontalAlignment="Left" Height="374.1" Margin="50,50,0,0" VerticalAlignment="Top" Width="950" Style="{DynamicResource AyTabControl}" TabStripPlacement="Top" >
            <TabItem Header="aaronyang生活">
                <TabItem.Background>
                    <LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
                        <GradientStop Color="#FFA1B8D3" Offset="0"/>
                        <GradientStop Color="#FFABC3DF" Offset="0.067"/>
                        <GradientStop Color="#FFA5B9D4" Offset="0.967"/>
                        <GradientStop Color="#FF194177" Offset="1"/>
                    </LinearGradientBrush>
                </TabItem.Background>
              <TextBlock FontSize="36" Text="aaronyang的生活" VerticalAlignment="Center" HorizontalAlignment="Center"/>
            </TabItem>
            <TabItem Header="aaronyang快递" >
                <Grid >
                    <TextBlock FontSize="36" Text="aaronyang的快递" VerticalAlignment="Center" HorizontalAlignment="Center"/>
                </Grid>
            </TabItem>
            <TabItem Header="aaronyang尊重">
                <Grid >
                    <TextBlock FontSize="36" Text="aaronyang的尊重" VerticalAlignment="Center" HorizontalAlignment="Center"/>
                </Grid>
            </TabItem>
        </TabControl>

效果图(只支持顶部样式):

Image 5.png

当然更好的AyTabControl效果预览:

QQ图片20150326175742.png

支持多种布局

动态图演示: 请点击http://www.ayjs.net/zb_users/upload/2015/03/201503271427419580606684.gif


推荐您阅读更多有关于“WPF4.5Ay.Framework.WPF,”的文章

猜你喜欢

已有1位网友发表了看法:

1#三台  2015-03-27 13:22:20 回复该评论
很好看!
av快递辛苦了

发表评论

必填

选填

选填

必填

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

  查看权限

抖音号:wpfui,可以看到我的很多作品效果

AYUI8社区版Github地址:前往获取

作者:杨洋(AaronYang简称AY,安徽六安人)目前是个人,还没公司AY唯一QQ:875556003和AY交流

高中学历,2015年1月17日开始,兴趣学习研究WPF,目前工作繁忙,不接任何活

声明:AYUI7个人与商用免费,源码可购买。部分DEMO不免费.AY主要靠卖技术服务挣钱

不是从我处购买的ayui7源码,我不提供任何技术服务,如果你举报从哪里买的,我可以帮你转正为我的客户,并送demo

查看捐赠

AYUI7.X MVC教程 更新如下:

第一课 第二课 程序加密教程

兼容XP到win10,vs2015/2017/2019,最新AYUI:7.6.5.5

vs2015 企业版密钥HM6NR-QXX7C-DFW2Y-8B82K-WTYJV

vs2017 企业版密钥NJVYC-BMHX2-G77MM-4XJMR-6Q8QF

标签列表