WPF 基础控件之 TabControl样式

article/2025/10/10 23:17:33

其他基础控件

1.Window
2.Button
3.CheckBox
4.ComboBox
5.DataGrid
6.DatePicker
7.Expander
8.GroupBox
9.ListBox
10.ListView
11.Menu
12.PasswordBox
13.TextBox
14.RadioButton
15.ToggleButton
16.Slider
17.TreeView

TabControl  实现下面的效果

94021372cbf43f730d7f3b711dea33d1.png

1)TabControl来实现动画;

  • TabControl分为横向和纵向;

  • 横向Border设置RenderTransformScaleTransform.ScaleY="1",动画控制ScaleTransform.ScaleX01

  • 纵向Border设置RenderTransformScaleTransform.ScaleX="1",动画控制ScaleTransform.ScaleY01

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:sys="clr-namespace:System;assembly=mscorlib"xmlns:wpfs="clr-namespace:WPFDevelopers.Minimal.Helpers"><ResourceDictionary.MergedDictionaries><ResourceDictionary Source="../Themes/Basic/ControlBasic.xaml"/><ResourceDictionary Source="../Themes/Basic/Animations.xaml"/></ResourceDictionary.MergedDictionaries><Thickness x:Key="BorderThickness">0,0,0,2</Thickness><Style x:Key="BaseTAndBTabItem" TargetType="{x:Type TabItem}" BasedOn="{StaticResource ControlBasicStyle}"><Setter Property="Cursor" Value="Hand" /><Setter Property="Background" Value="Transparent" /><Setter Property="MinHeight" Value="48"/><Setter Property="MinWidth" Value="100"/><Setter Property="BorderThickness" Value="{StaticResource BorderThickness}"/><Setter Property="Template"><Setter.Value><ControlTemplate TargetType="{x:Type TabItem}"><Grid Background="{TemplateBinding Background}"><VisualStateManager.VisualStateGroups><VisualStateGroup x:Name="SelectionStates"><VisualState x:Name="Unselected" /><VisualState x:Name="Selected"><Storyboard><DoubleAnimation Duration="00:00:.2"To="1"Storyboard.TargetName="PART_Border"Storyboard.TargetProperty="(Border.RenderTransform).(ScaleTransform.ScaleX)"/></Storyboard></VisualState></VisualStateGroup><VisualStateGroup x:Name="CommonStates"><VisualState x:Name="Normal" /><VisualState x:Name="MouseOver" /><VisualState x:Name="Disabled"/></VisualStateGroup></VisualStateManager.VisualStateGroups><Border x:Name="PART_Border" BorderThickness="{TemplateBinding BorderThickness}"RenderTransformOrigin=".5,.5"><Border.RenderTransform><ScaleTransform ScaleX="0" ScaleY="1"/></Border.RenderTransform></Border><ContentPresenter ContentSource="Header"VerticalAlignment="Center" HorizontalAlignment="Center"/></Grid><ControlTemplate.Triggers><Trigger Property="IsSelected" Value="True"><Setter TargetName="PART_Border" Property="BorderBrush" Value="{DynamicResource PrimaryNormalSolidColorBrush}" /><Setter Property="Background" Value="{DynamicResource DefaultBackgroundSolidColorBrush}" /><!--<Setter Property="FontWeight" Value="Black"/>--><Setter Property="Foreground" Value="{DynamicResource PrimaryNormalSolidColorBrush}"/></Trigger><Trigger Property="IsMouseOver" Value="True"><Setter Property="Foreground" Value="{DynamicResource PrimaryNormalSolidColorBrush}"/></Trigger></ControlTemplate.Triggers></ControlTemplate></Setter.Value></Setter></Style><Style x:Key="BaseLAndRTabItem" TargetType="{x:Type TabItem}" BasedOn="{StaticResource ControlBasicStyle}"><Setter Property="Cursor" Value="Hand" /><Setter Property="Background" Value="Transparent" /><Setter Property="MinHeight" Value="48"/><Setter Property="MinWidth" Value="100"/><Setter Property="BorderThickness" Value="{StaticResource BorderThickness}"/><Setter Property="Template"><Setter.Value><ControlTemplate TargetType="{x:Type TabItem}"><Grid Background="{TemplateBinding Background}"><VisualStateManager.VisualStateGroups><VisualStateGroup x:Name="SelectionStates"><VisualState x:Name="Unselected" /><VisualState x:Name="Selected"><Storyboard><DoubleAnimation Duration="00:00:.2"To="1"Storyboard.TargetName="PART_Border"Storyboard.TargetProperty="(Border.RenderTransform).(ScaleTransform.ScaleY)"/></Storyboard></VisualState></VisualStateGroup><VisualStateGroup x:Name="CommonStates"><VisualState x:Name="Normal" /><VisualState x:Name="MouseOver" /><VisualState x:Name="Disabled"/></VisualStateGroup></VisualStateManager.VisualStateGroups><Border x:Name="PART_Border" BorderThickness="{TemplateBinding BorderThickness}"RenderTransformOrigin=".5,.5"><Border.RenderTransform><ScaleTransform ScaleX="1" ScaleY="0"/></Border.RenderTransform></Border><ContentPresenter ContentSource="Header"VerticalAlignment="Center" HorizontalAlignment="Center"/></Grid><ControlTemplate.Triggers><Trigger Property="IsSelected" Value="True"><Setter TargetName="PART_Border" Property="BorderBrush" Value="{DynamicResource PrimaryNormalSolidColorBrush}" /><Setter Property="Background" Value="{DynamicResource DefaultBackgroundSolidColorBrush}" /><!--<Setter Property="FontWeight" Value="Black"/>--><Setter Property="Foreground" Value="{DynamicResource PrimaryNormalSolidColorBrush}"/></Trigger><Trigger Property="IsMouseOver" Value="True"><Setter Property="Foreground" Value="{DynamicResource PrimaryNormalSolidColorBrush}"/></Trigger></ControlTemplate.Triggers></ControlTemplate></Setter.Value></Setter></Style><Style x:Key="LeftTabItem" TargetType="{x:Type TabItem}" BasedOn="{StaticResource BaseLAndRTabItem}"><Setter Property="BorderThickness" Value="0,0,2,0"/></Style><Style x:Key="RightTabItem" TargetType="{x:Type TabItem}" BasedOn="{StaticResource BaseLAndRTabItem}"><Setter Property="BorderThickness" Value="2,0,0,0"/></Style><Style x:Key="TopTabItem" TargetType="{x:Type TabItem}" BasedOn="{StaticResource BaseTAndBTabItem}"><Setter Property="BorderThickness" Value="0,0,0,2"/></Style><Style x:Key="BottomTabItem" TargetType="{x:Type TabItem}" BasedOn="{StaticResource BaseTAndBTabItem}"><Setter Property="BorderThickness" Value="0,2,0,0"/></Style><Style TargetType="{x:Type TabControl}" BasedOn="{StaticResource ControlBasicStyle}"><Setter Property="TabStripPlacement" Value="Top" /><!--<Setter Property="Margin" Value="2" />--><!--<Setter Property="Padding" Value="2"/>--><Setter Property="Background" Value="{DynamicResource WhiteSolidColorBrush}" /><Setter Property="ItemContainerStyle" Value="{StaticResource TopTabItem}"/><Setter Property="Template"><Setter.Value><ControlTemplate TargetType="{x:Type TabControl}"><Grid ClipToBounds="True" SnapsToDevicePixels="True" KeyboardNavigation.TabNavigation="Local"><Grid.ColumnDefinitions><ColumnDefinition Name="ColumnDefinition0"/><ColumnDefinition Width="0" Name="ColumnDefinition1" /></Grid.ColumnDefinitions><Grid.RowDefinitions><RowDefinition Height="Auto" Name="RowDefinition0" /><RowDefinition Height="*" Name="RowDefinition1" /></Grid.RowDefinitions><Border x:Name="HeaderBorder" BorderBrush="{DynamicResource BaseSolidColorBrush}" BorderThickness="0,0,0,1" Grid.Row="0"Background="{DynamicResource WhiteSolidColorBrush}"><TabPanel IsItemsHost="True"Name="HeaderPanel" Panel.ZIndex="1"KeyboardNavigation.TabIndex="1"/></Border><Grid Name="ContentPanel"KeyboardNavigation.TabIndex="2" KeyboardNavigation.TabNavigation="Local" KeyboardNavigation.DirectionalNavigation="Contained" Grid.Column="0" Grid.Row="1"><Border><ContentPresenter Content="{TemplateBinding SelectedContent}" ContentTemplate="{TemplateBinding SelectedContentTemplate}" ContentStringFormat="{TemplateBinding SelectedContentStringFormat}" ContentSource="SelectedContent" Name="PART_SelectedContentHost" Margin="2" SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}"  /></Border></Grid></Grid><ControlTemplate.Triggers><Trigger Property="TabControl.TabStripPlacement" Value="Bottom"><Setter TargetName="RowDefinition0" Property="RowDefinition.Height" Value="*" /><Setter TargetName="RowDefinition1" Property="RowDefinition.Height" Value="Auto" /><Setter TargetName="HeaderBorder" Property="Grid.Row" Value="1" /><Setter TargetName="ContentPanel" Property="Grid.Row" Value="0" /><Setter TargetName="HeaderBorder" Property="BorderThickness" Value="0,1,0,0" /><Setter Property="ItemContainerStyle" Value="{StaticResource BottomTabItem}"/></Trigger><Trigger Property="TabControl.TabStripPlacement" Value="Left"><Setter TargetName="ContentPanel" Property="Grid.Row" Value="0" /><Setter TargetName="ContentPanel" Property="Grid.Column" Value="1" /><Setter TargetName="ColumnDefinition0" Property="ColumnDefinition.Width" Value="Auto" /><Setter TargetName="ColumnDefinition1" Property="ColumnDefinition.Width" Value="*" /><Setter TargetName="RowDefinition0" Property="RowDefinition.Height" Value="*" /><Setter TargetName="RowDefinition1" Property="RowDefinition.Height" Value="0" /><Setter TargetName="HeaderBorder" Property="BorderThickness" Value="0,0,1,0" /><Setter Property="ItemContainerStyle" Value="{StaticResource LeftTabItem}"/></Trigger><Trigger Property="TabControl.TabStripPlacement" Value="Right"><Setter TargetName="ContentPanel" Property="Grid.Row" Value="0" /><Setter TargetName="HeaderBorder" Property="Grid.Column" Value="1" /><Setter TargetName="ContentPanel" Property="Grid.Column" Value="0" /><Setter TargetName="ColumnDefinition0" Property="ColumnDefinition.Width" Value="*" /><Setter TargetName="ColumnDefinition1" Property="ColumnDefinition.Width" Value="Auto" /><Setter TargetName="RowDefinition0" Property="RowDefinition.Height" Value="*" /><Setter TargetName="RowDefinition1" Property="RowDefinition.Height" Value="0" /><Setter TargetName="HeaderBorder" Property="BorderThickness" Value="1,0,0,0" /><Setter Property="ItemContainerStyle" Value="{StaticResource RightTabItem}"/></Trigger></ControlTemplate.Triggers></ControlTemplate></Setter.Value></Setter></Style></ResourceDictionary>

2)Styles.TabControl.xaml 代码如下;

<UniformGrid Columns="2" Rows="2" Margin="0,10"><UniformGrid.Resources><Style TargetType="{x:Type Rectangle}"><Setter Property="Width" Value="{x:Static SystemParameters.PrimaryScreenWidth}"/><Setter Property="Height" Value="400"/></Style></UniformGrid.Resources><TabControl><TabItem Header="TabItem1"><Rectangle Fill="{DynamicResource DangerSolidColorBrush}"/></TabItem><TabItem Header="TabItem2"><Rectangle Fill="{DynamicResource InfoSolidColorBrush}"/></TabItem><TabItem Header="TabItem3" ><Rectangle Fill="{DynamicResource WarningSolidColorBrush}"/></TabItem></TabControl><TabControl TabStripPlacement="Bottom"><TabItem Header="TabItem1"><Rectangle Fill="{DynamicResource InfoSolidColorBrush}"/></TabItem><TabItem Header="TabItem2"><Rectangle Fill="{DynamicResource DangerSolidColorBrush}"/></TabItem><TabItem Header="TabItem3" ><Rectangle Fill="{DynamicResource WarningSolidColorBrush}"/></TabItem></TabControl><TabControl TabStripPlacement="Left"><TabItem Header="TabItem1"><Rectangle Fill="{DynamicResource WarningSolidColorBrush}"/></TabItem><TabItem Header="TabItem2"><Rectangle Fill="{DynamicResource InfoSolidColorBrush}"/></TabItem><TabItem Header="TabItem3" ><Rectangle Fill="{DynamicResource DangerSolidColorBrush}"/></TabItem></TabControl><TabControl TabStripPlacement="Right" IsEnabled="False"><TabItem Header="TabItem1"><Rectangle Fill="{DynamicResource SuccessSolidColorBrush}"/></TabItem><TabItem Header="TabItem2"><Rectangle Fill="{DynamicResource InfoSolidColorBrush}"/></TabItem><TabItem Header="TabItem3" ><Rectangle Fill="{DynamicResource WarningSolidColorBrush}"/></TabItem></TabControl></UniformGrid>

Nuget Install-Package WPFDevelopers.Minimal

a3cc8a81d15daeaf0059e62e04ae36f0.gif

[1][2]

参考资料

[1]

GitHub: https://github.com/WPFDevelopersOrg

[2]

Gitee: https://gitee.com/WPFDevelopersOrg


http://chatgpt.dhexx.cn/article/AQoS1VQ1.shtml

相关文章

WPF TabControl美化

实现效果 XMAL样式 <Window.Resources><!-- TabItem的样式 --><Style TargetType"{x:Type TabItem}"><Setter Property"Template"><Setter.Value><ControlTemplate TargetType"{x:Type TabItem}"><Gr…

WPF动态加载TabControl

主要讲一下如何通过点击菜单&#xff0c;实现动态加载TabControl的功能&#xff0c;准确来说应该是动态加载TabItem,要实现这个功能&#xff0c;我们需要解决两个问题&#xff1a; 点击菜单的时候&#xff0c;需要传进来一个你要加载的UserControl控件的名称&#xff0c;让程序…

C# TabControl

C# TabControl 你好&#xff01; 这是你第一次使用 Markdown编辑器 所展示的欢迎页。如果你想学习如何使用Markdown编辑器, 可以仔细阅读这篇文章&#xff0c;了解一下Markdown的基本语法知识。 新的改变 我们对Markdown编辑器进行了一些功能拓展与语法支持&#xff0c;除了标…

TabControl

jquery主体&#xff1a; var TabControl function (ops) {this._ops {items: ops.items || [],hashItems: {},selectedIndex: ops.selectedIndex || 0};this._element $(ops.element);this._tabContainerId "ui-tabcontrol-container-";this._convertHashItems()…

WinForm TabControl美化

一、简述 TabControl控件是winform里非常常用的一个控件&#xff0c;但是默认的tab控件的标签页和文字颜色都是无法修改的。有时候我们会要用到竖排列的标签页&#xff0c;或者想要更改标签页的背景颜色和字体时&#xff0c;自带的TabControl就满足不了我们的需求了&#xff0…

MFC中选项卡TabControl控件的用法

前言&#xff1a;我这里的开发环境是VS2010&#xff0c;其它不同的开发环境可能会有所差别&#xff0c;但绝不会差太多&#xff0c;其根本方法一般是不会变的。 选项卡控件(英文名&#xff1a;TabControl),这个控件使用在开发一些比较复杂&#xff0c;和用户交互性比较多的软件…

C#中TabControl相关用法

最近在用C#做项目时&#xff0c;用到TabControl这个控件&#xff0c;将学到的东西做个总结&#xff1a; 一、拖一个TabControl控件到窗口上&#xff0c;在控件上点击右键&#xff0c;可以添加选项卡/删除选项卡&#xff1b;或者在属性中找到TabPages,点击进去&#xff0c;可以看…

【Wayland】Weston启动流程分析

Weston启动流程分析 Weston是Wayland Compositor的实现。其Server端作为独立的进程运行在系统中。MakeFile中编译成果为&#xff0c;“weston”的可执行程序MakeFile.am(weston 2.0.0) bin_PROGRAMS westonweston_LDFLAGS -export-dynamic weston_CPPFLAGS $(AM_CPPFLAGS)…

Weston 纹理倒置(render-gl)

纹理倒置 背景 在 render-gl 接入 frame buffer object 实现 off-screen 渲染后,发现得到的渲染图发生了180的倒置. 查阅了有关资料后,在 eglspec.1.5 中的 2.2.2.1 Native Surface Coordinate Systems 找到了答案: The coordinate system for native windows and pixmaps …

【Wayland】Wayland简介与定制指导

Wayland与Weston简介 由于某些原因。移植并定制一套基于Wayland的Compositor。Wayland与Weston&#xff0c;是两个相辅相成的概念。这里简单总结一下&#xff1a; wayland是一套为“显示”服务的协议&#xff0c;基于C/S结构。它定制了一套标准的接口、基本通信方式。wayland…

display:weston:weston-simple-egl

写在前面&#xff1a; 客户端渲染 在Wayland架构中&#xff0c;客户端UI的所有呈现均由客户端代码执行&#xff0c;通常由客户端使用的图形工具包执行。 图形工具箱可以使用其希望呈现UI元素的任何方法&#xff1a;在CPU上进行软件呈现&#xff0c;使用GLES进行硬件呈现。 W…

Ubuntu 20.04 X86成功编译运行wayland、wayland-protocols、weston,亲测有效,踩了很多坑,完美解决。

编译前期准备&#xff1a; 1、更换国内源&#xff1a; #添加阿里源 deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse deb http://mirrors.aliyun.c…

weston 窗口管理 (1)

窗口管理 (1) 一、概述 在传统嵌入式场景下,通常只会运行一个UI程序,故相当于单窗口程序,无需桌面服务器的介入;在桌面系统下,对于每一个UI程序而言,它们的行为相比于嵌入式场景仍然没有发生改变,其对接的仍然是窗口,只不过在同一个时刻允许多个UI程序同时运行. 无论如何对于…

weston 简介

参考???weston wiki Weston - Gentoo Wiki weston (1): Linux man pages – code.tools Weston-1.12.0 非常详尽&#xff0c;多图慎入&#xff1a;Wayland与Weston简介 - 云社区 - 腾讯云 什么是weston&#xff1f; Wayland是一套display server(Wayland compositor)与…

waylandweston

简单地说&#xff0c;Wayland是一套display server(Wayland compositor)与client间的通信协议&#xff0c;而Weston是Wayland compositor的参考实现。其官网为http://wayland.freedesktop.org/。它们定位于在Linux上替换X图形系统。X图形系统经历了30年左右的发展&#xff0c;其…

weston 1: 编译与运行傻瓜教程

本人Kubuntu版本是22.04 sudo apt-get update sudo apt-get upgrade 进入主目录 cd $HOME/ mkdir install mkdir works vim ~/.bashrc export WLD$HOME/install source ~/.bashrc cd works wayland git clone https://gitlab.freedesktop.org/wayland/wayland.git cd …

weston input 概述

weston input 概述 零、前言 本文描述了有关于 weston (基于 wayland 协议一种显示服务器的实现) 中有关于输入设备管理的部分;为了聚焦于此,本文不会对 weston 整体或 wayland 协议进行过多的阐述. 考虑到读者可能存在不同的需求,采用分层次的描述方式,主要面向以下两类人群…

weston 2: 登录后直接启动weston配置

本人Kubuntu版本是22.04 名词&#xff1a;SDDM&#xff08;SDDM - Arch Linux 中文维基&#xff09;显示管理器 配置流程如下&#xff1a; 1.修改配置文件 a.配置.bashrc vim ~/.bashrc //以下内容删除 #export WLD$HOME/install #export LD_LIBRARY_PATH$WLD/lib/x86_64-…

Weston介绍

Weston结构说明 Weston源码结构 clients&#xff1a;wayland显示客户端应用 compositor&#xff1a;合成器进程&#xff08;服务端&#xff09;&#xff0c;窗体风 格样式处理 libweston&#xff1a;合成器以及客户端渲染处理以及驱动实现方式&#xff0c;以及wayland服务与客户…

Wayland/Weston 启动方式简介

前言 本文简单介绍 Weston 常用的几种 backend 启动方式。目前最新的 Weston 8.0.0 支持如下几种 backend&#xff1a; drm-backendfbdev-backendheadless-backendrdp-backendwayland-backendx11-backend 其中 headless-backend 不带任何 UI 界面&#xff0c;主要用于 westo…