WPF TabControl Styles

article/2025/10/10 23:24:53

WPF TabControl Styles

水平使用的TabControl

效果:
在这里插入图片描述

样式资源

<!-- 顶部TabControl控件样式 --><SolidColorBrush x:Key="TabItem.Static.Background" Color="White"/><SolidColorBrush x:Key="TabItem.Static.Border" Color="#ACACAC"/><SolidColorBrush x:Key="TabItem.MouseOver.Border" Color="#7EB4EA"/><SolidColorBrush x:Key="TabItem.Disabled.Background" Color="#F0F0F0"/><SolidColorBrush x:Key="TabItem.Disabled.Border" Color="#D9D9D9"/><SolidColorBrush x:Key="TabItem.Selected.Border" Color="#ACACAC"/><SolidColorBrush x:Key="TabItem.Selected.Background" Color="#FFFFFF"/><Style x:Key="TabItem.Style.TopTabStripPlacement" TargetType="{x:Type TabItem}"><Setter Property="Foreground" Value="Black"/><Setter Property="Background" Value="{StaticResource TabItem.Static.Background}"/><Setter Property="BorderBrush" Value="{StaticResource TabItem.Static.Border}"/><Setter Property="Margin" Value="0"/><Setter Property="Padding" Value="0,8,0,8"/><Setter Property="HorizontalContentAlignment" Value="Stretch"/><Setter Property="VerticalContentAlignment" Value="Stretch"/><Setter Property="Template"><Setter.Value><ControlTemplate TargetType="{x:Type TabItem}"><Border Padding="0 0 20 0" ><Grid x:Name="templateRoot" SnapsToDevicePixels="true" ><Border Background="{TemplateBinding Background}"></Border><ContentPresenter x:Name="contentPresenter" ContentSource="Header" Focusable="False"HorizontalAlignment="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" TextBlock.FontSize="12" TextBlock.FontWeight="UltraBlack" TextBlock.FontFamily="幼圆"SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"VerticalAlignment="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/><Grid Height="2" x:Name="bottomLine" VerticalAlignment="Bottom" Background="#498FD7" Visibility="Hidden"></Grid></Grid></Border><ControlTemplate.Triggers><Trigger Property="IsEnabled" Value="false"><Setter Property="Opacity" TargetName="contentPresenter" Value="0.56"/></Trigger><Trigger Property="IsSelected" Value="true"><Setter Property="Panel.ZIndex" Value="1"/><Setter Property="Opacity" TargetName="templateRoot" Value="1"/><Setter Property="Visibility" TargetName="bottomLine" Value="Visible"/><Setter Property="Foreground" Value="#498FD7"/></Trigger></ControlTemplate.Triggers></ControlTemplate></Setter.Value></Setter></Style><Style x:Key="TabControl.Style.TopTabStripPlacement" TargetType="{x:Type TabControl}"><Setter Property="Padding" Value="0"/><Setter Property="HorizontalContentAlignment" Value="Center"/><Setter Property="VerticalContentAlignment" Value="Center"/><Setter Property="Background" Value="{StaticResource TabItem.Selected.Background}"/><Setter Property="BorderBrush" Value="{StaticResource TabItem.Selected.Border}"/><Setter Property="BorderThickness" Value="0"/><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="RowDefinition2" Height="Auto"/><RowDefinition x:Name="RowDefinition1" Height="*"/></Grid.RowDefinitions><TabPanel x:Name="headerPanel" Grid.Column="0" IsItemsHost="true"  Grid.Row="0" KeyboardNavigation.TabIndex="1" Panel.ZIndex="1"/><Grid Grid.Row="1" Background="#A8D3FE" VerticalAlignment="Top" Height="1"></Grid><Border x:Name="contentPanel" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Grid.Column="0" KeyboardNavigation.DirectionalNavigation="Contained" Grid.Row="2" KeyboardNavigation.TabIndex="2" KeyboardNavigation.TabNavigation="Local"><ContentPresenter x:Name="PART_SelectedContentHost" ContentSource="SelectedContent" Margin="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/></Border></Grid><ControlTemplate.Triggers><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>

MainWindow.xaml使用

<Window x:Class="TabControlStyle.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.microsoft.com/expression/blend/2008"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"xmlns:local="clr-namespace:TabControlStyle"mc:Ignorable="d"Title="MainWindow" Height="450" Width="800"><Grid><Border  Height="212.493"  VerticalAlignment="Center" ><TabControl Width="441.81" HorizontalAlignment="Center"  Style="{DynamicResource TabControl.Style.TopTabStripPlacement}"><TabItem Header="检测" Style="{DynamicResource TabItem.Style.TopTabStripPlacement}"><WrapPanel Background="White" Margin="0 5"><Border BorderBrush="#FFD2DDE8" BorderThickness="1" Width="100" Height="150"/></WrapPanel></TabItem><TabItem Header="控制" Style="{DynamicResource TabItem.Style.TopTabStripPlacement}"><Grid Background="#FFE5E5E5"/></TabItem><TabItem Header="日志" Style="{DynamicResource TabItem.Style.TopTabStripPlacement}"><Grid Background="#FFE5E5E5"/></TabItem></TabControl></Border></Grid>
</Window>

积跬步以至千里:) (:一阵没来由的风


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

相关文章

MFC tabcontrol切换界面

1.添加控件tabcontrol。 2.切换到资源界面->Dialog->插入Dialog&#xff0c;创建两个Dialog界面。 3.为新建的两个Dialog添加类&#xff0c;在新建的Dialog界面右键类向导添加对应的类。 4.添加TabSheet.cpp 和TabSheet.h 这两个文件从网上下载即可&#xff0c;具体源码如…

TabControl控件

点餐用到的控件&#xff1a; 1&#xff09;TabControl: 管理并向用户显示可以包含控件和组件的相关选项卡的信息 2&#xff09;ComboBox: 显示一个可编辑的文本框&#xff0c;其中包含一个允许值下拉列表 3&#xff09;DateTimePicker: 允许用户设定日期和时间&#x…

WPF 控件专题 TabControl控件详解

1、TabControl 介绍 TabControl 表示包含多个项的控件&#xff0c;这些项共享屏幕上的同一空间&#xff0c;每个区域都可以通过单击通常位于控件顶部的选项卡标题来访问。 也叫选项卡控件。 *******************************************************************************…

WPF 基础控件之 TabControl样式

其他基础控件 1.Window2.Button3.CheckBox4.ComboBox5.DataGrid 6.DatePicker7.Expander8.GroupBox9.ListBox10.ListView11.Menu12.PasswordBox13.TextBox14.RadioButton15.ToggleButton16.Slider 17.TreeView TabControl 实现下面的效果 1&#xff09;TabControl来实现动画&…

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 …