当前位置: 首页 > news >正文

WPF之可翻转面板

1,创建翻转面板的资源字典:FlippPanel.xaml。

  • 无外观控件同样必须给样式指定类型( <ControlTemplate TargetType="ss:FlipPanel">),相关详情参考:WPF之创建无外观控件-CSDN博客)。
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:ss="clr-namespace:无外观控件"xmlns:local="clr-namespace:无外观控件.Themes"><Style TargetType="ss:FlipPanel"><Setter Property="Template"><Setter.Value><ControlTemplate TargetType="ss:FlipPanel"><Grid><Grid.RowDefinitions><RowDefinition Height="auto"></RowDefinition><RowDefinition Height="auto"></RowDefinition></Grid.RowDefinitions><!--1,为给模板添加VisualStateManager元素,模板必须使用布局面板。布局面板包含控件的两个可视化对象和VisualStateManager元素(该元素不可见)--><VisualStateManager.VisualStateGroups><VisualStateGroup Name="ViewStates"><VisualStateGroup.Transitions><!--两个可视对象切换时间,以及伴随的ToggleButton切换动画--><VisualTransition To="Normal" GeneratedDuration="00:00:01"><Storyboard ><DoubleAnimation  To="0" Storyboard.TargetName="PART_Rota" Storyboard.TargetProperty="Angle" ></DoubleAnimation></Storyboard></VisualTransition><VisualTransition To="Flipped" GeneratedDuration="00:00:2"><Storyboard ><DoubleAnimation  To="180" Storyboard.TargetName="PART_Rota" Storyboard.TargetProperty="Angle" ></DoubleAnimation></Storyboard></VisualTransition></VisualStateGroup.Transitions><VisualState Name="Normal"><Storyboard ><DoubleAnimation To="0" Storyboard.TargetName="front" Storyboard.TargetProperty="Opacity" Duration="00:00:00"></DoubleAnimation><!--ToggleButton旋转动画不能省,否则动画异常--><DoubleAnimation  To="0"  Storyboard.TargetName="PART_Rota" Storyboard.TargetProperty="Angle"></DoubleAnimation></Storyboard></VisualState><VisualState Name="Flipped"><Storyboard ><DoubleAnimation To="0" Storyboard.TargetName="back" Storyboard.TargetProperty="Opacity" Duration="00:00:00"></DoubleAnimation><!--ToggleButton旋转动画不能省,否则动画异常--><DoubleAnimation  To="180" Storyboard.TargetName="PART_Rota" Storyboard.TargetProperty="Angle" Duration="00:00:00" ></DoubleAnimation></Storyboard></VisualState></VisualStateGroup></VisualStateManager.VisualStateGroups><Border  x:Name="front" BorderBrush="{TemplateBinding BorderBrush}" CornerRadius="{TemplateBinding CornerRadius}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}"><ContentPresenter Content="{TemplateBinding FrontContent}"></ContentPresenter></Border><Border x:Name="back" BorderBrush="{TemplateBinding BorderBrush}" CornerRadius="{TemplateBinding CornerRadius}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}"><ContentPresenter Content="{TemplateBinding BackContent}"></ContentPresenter></Border><ToggleButton  Grid.Row="1" Height="40" Name="FlipButton" RenderTransformOrigin="0.5,0.5"><ToggleButton.RenderTransform><RotateTransform x:Name="PART_Rota" ></RotateTransform></ToggleButton.RenderTransform><ToggleButton.Template><ControlTemplate TargetType="ToggleButton"><ToggleButton Grid.Column="1" Grid.Row="1"  Name="FlipButton"><ToggleButton.Template><ControlTemplate TargetType="ToggleButton"><Rectangle ><Rectangle.Fill><DrawingBrush Stretch="None"><DrawingBrush.Drawing><GeometryDrawing Brush="White"><GeometryDrawing.Pen><Pen Brush="Black" Thickness="2"></Pen></GeometryDrawing.Pen><GeometryDrawing.Geometry><GeometryGroup><EllipseGeometry RadiusX="15" RadiusY="15"></EllipseGeometry><CombinedGeometry GeometryCombineMode="Intersect"><CombinedGeometry.Geometry1><EllipseGeometry RadiusX="7.5" RadiusY="7.5"></EllipseGeometry></CombinedGeometry.Geometry1><CombinedGeometry.Geometry2><PathGeometry   Figures="M-7.5,0 L0,-7.5 L7.5,-7.5 L0,0 L7.5,7.5 L0,7.5 Z"></PathGeometry></CombinedGeometry.Geometry2></CombinedGeometry></GeometryGroup></GeometryDrawing.Geometry></GeometryDrawing></DrawingBrush.Drawing></DrawingBrush></Rectangle.Fill></Rectangle></ControlTemplate></ToggleButton.Template></ToggleButton></ControlTemplate></ToggleButton.Template></ToggleButton></Grid></ControlTemplate></Setter.Value></Setter></Style>
</ResourceDictionary>
  • VisualStateManager只能在布局面板下进行状态管理。

2,在generic.xaml中添加资源字典FlipPanel.xaml.

<ResourceDictionaryxmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"><ResourceDictionary.MergedDictionaries><ResourceDictionary Source="无外观控件;component/Themes/colorpicker.xaml"></ResourceDictionary><ResourceDictionary Source="无外观控件;component/Themes/FlipPanel.xaml"></ResourceDictionary></ResourceDictionary.MergedDictionaries>
</ResourceDictionary>

3,编写代码

 [TemplatePart(Name = "FlipButton", Type =typeof(ToggleButton))]//该特性只是进行提示,无其他意义,可舍去[TemplateVisualState(GroupName = "Normal", Name = "ViewStates")]//该特性提示存在可视化切换,无其他实际意义,可舍去[TemplateVisualState(GroupName = "Flipped", Name = "ViewStates")]public class FlipPanel : Control{public static readonly DependencyProperty CornerRadiusProperty;public static readonly DependencyProperty FrontContentProperty;public static readonly DependencyProperty BackContentProperty;public static readonly DependencyProperty IsFlippedProperty;static FlipPanel(){DefaultStyleKeyProperty.OverrideMetadata(typeof(FlipPanel), new FrameworkPropertyMetadata(typeof(FlipPanel)));CornerRadiusProperty = DependencyProperty.Register("CornerRadius", typeof(CornerRadius), typeof(FlipPanel));FrontContentProperty = DependencyProperty.Register("FrontContent", typeof(object), typeof(FlipPanel));BackContentProperty = DependencyProperty.Register("BackContent", typeof(object), typeof(FlipPanel));IsFlippedProperty = DependencyProperty.Register("IsFlipped", typeof(bool), typeof(FlipPanel));}/// <summary>/// 设置控件边框倒角/// </summary>public CornerRadius CornerRadius{get{return (CornerRadius)this.GetValue(CornerRadiusProperty);}set{this.SetValue(CornerRadiusProperty, value);}}/// <summary>/// 前置内容/// </summary>public object FrontContent{get{return this.GetValue(FrontContentProperty);}set{this.SetValue(FrontContentProperty, value);}}/// <summary>/// 后置内容/// </summary>public object BackContent{get{return GetValue(BackContentProperty);}set{this.SetValue(BackContentProperty, value);}}/// <summary>/// 是否翻转/// </summary>public bool IsFlipped{get{return (bool)GetValue(IsFlippedProperty);}set{SetValue(IsFlippedProperty, value);ChangeVisualState(true);}}public override void OnApplyTemplate(){ToggleButton btn = GetTemplateChild("FlipButton") as ToggleButton;btn.Click += Btn_Click;ChangeVisualState(false);base.OnApplyTemplate();}private void Btn_Click(object sender, RoutedEventArgs e){IsFlipped = !IsFlipped;}void ChangeVisualState(bool useTransition){if (IsFlipped){VisualStateManager.GoToState(this, "Flipped", useTransition);}else{VisualStateManager.GoToState(this, "Normal", useTransition);}}}

4,在UI上添加控件

<local:FlipPanel Grid.Row="1" IsFlipped="True"><local:FlipPanel.FrontContent><StackPanel><Button Content="前1"></Button><Button Content="前2"></Button><Button Content="前3"></Button><Button Content="前3"></Button><Button Content="前4"></Button></StackPanel></local:FlipPanel.FrontContent><local:FlipPanel.BackContent><StackPanel><Button Content="后1"></Button></StackPanel></local:FlipPanel.BackContent></local:FlipPanel>

5,效果

6,Demo 链接

https://download.csdn.net/download/lingxiao16888/89253829?spm=1001.2014.3001.5501

相关文章:

WPF之可翻转面板

1&#xff0c;创建翻转面板的资源字典&#xff1a;FlippPanel.xaml。 无外观控件同样必须给样式指定类型&#xff08; <ControlTemplate TargetType"ss:FlipPanel">&#xff09;&#xff0c;相关详情参考&#xff1a;WPF之创建无外观控件-CSDN博客&#xff09…...

【深度学习】--slowfast视频理解数据集处理pipeline

官网指引&#xff1a; facebookresearch SlowFast &#xff1a;https://github.com/facebookresearch/SlowFast 进入dataset&#xff1a;https://github.com/facebookresearch/SlowFast/blob/main/slowfast/datasets/DATASET.md 这里面的东西需要通读&#xff0c;但是不要过于…...

ArcGIS10.2能用了10.2.2不行了(解决)

前两天我们的推文介绍了 ArcGIS10.2系列许可到期解决方案-CSDN博客文章浏览阅读2次。本文手机码字&#xff0c;不排版了。 昨晚&#xff08;2021\12\17&#xff09;12点后&#xff0c;收到很多学员反馈 ArcGIS10.2系列软件突然崩溃。更有的&#xff0c;今天全单位崩溃。​提示许…...

mysql查询表信息(表名、表结构、字段信息等)

MySQL中&#xff0c;您可以使用以下SQL查询数据库的表信息或者某个表中具体的信息&#xff0c;例如&#xff1a;字段、字段描述、索引等&#xff0c;以下为具体的SQL&#xff1a; 1、查询数据库所有表信息&#xff08;表名/表描述&#xff09; SELECTtable_name name,TABLE_C…...

【MySQL探索之旅】JDBC (Java连接MySQL数据库)

&#x1f4da;博客主页&#xff1a;爱敲代码的小杨. ✨专栏&#xff1a;《Java SE语法》 | 《数据结构与算法》 | 《C生万物》 |《MySQL探索之旅》 |《Web世界探险家》 ❤️感谢大家点赞&#x1f44d;&#x1f3fb;收藏⭐评论✍&#x1f3fb;&#xff0c;您的三连就是我持续更…...

tomcat-GC溢出

背景 一个项目需要导出大量的数据&#xff0c;导致GC但是这个项目在本地能够运行&#xff0c;但是在服务器上就不能运行本地和服务器的区别&#xff1a;NGINX和TOMCATGC和NGINX无关&#xff0c;那么就是Tomcat分配JVM的堆内存的容量不够 错误解决思路 网上教了一些查看JVM的大小…...

结合场景,浅谈深浅度拷贝

有两段代码是这样的&#xff1a; A段&#xff1a; List<String> list1 new ArrayList<>(); Bear B new Bear(); for(Apple apple : apples){B.url apple.url;B.content apple.content;list1.add(Bear); } B段&#xff1a; List<String> list1 new A…...

生成指定范围的随机整数

private static final Random RANDOM new Random();// 生成指定范围的随机整数public static int generateRandomInt(int min, int max) {return RANDOM.nextInt(max - min 1) min;}public static void main(String[] args) {Integer count 5;Integer randomInt generateR…...

少的缓存穿透是缓存击穿,大量的是缓存雪崩

只要请求穿过了缓存层&#xff0c;直接打到了数据库&#xff0c;我就把这个现象理解为缓存穿透。 只要缓存失效了&#xff0c;就会出现缓存穿透&#xff0c;然后根据失效缓存数量的多少&#xff0c;划分出缓存击穿和缓存雪崩 缓存一致性 先改redis再改mysql。...

设备能耗数据在线监测

在追求可持续发展和绿色经济的当下&#xff0c;企业对于设备能耗的管理愈发重视。设备能耗数据在线监测&#xff0c;不仅能帮助企业实时掌握设备的运行状况&#xff0c;还能为企业节能减排、降低运营成本提供有力支持。HiWoo Cloud平台凭借其先进的技术和丰富的经验&#xff0c…...

springboot整合websocket,超简单入门

springBoot整合webSocket&#xff0c;超简单入门 webSocket简洁 WebSocket 是一种基于 TCP 协议的全双工通信协议&#xff0c;它允许客户端和服务器之间建立持久的、双向的通信连接。相比传统的 HTTP 请求 - 响应模式&#xff0c;WebSocket 提供了实时、低延迟的数据传输能力。…...

代码随想录算法训练营第三十四天| 860.柠檬水找零 406.根据身高重建队列 452. 用最少数量的箭引爆气球

860.柠檬水找零 题目链接 思路 三种情况&#xff0c;一种贪心&#xff0c;在bill为20时&#xff0c;有一次贪心选择&#xff1a;优先考虑先找105&#xff0c;再考虑找3*5&#xff0c;因为5可以用于bill10和bill20两种情况 解题方法 第一种&#xff1a;bill5,直接收 第二种…...

ICode国际青少年编程竞赛- Python-2级训练场-识别循环规律2

ICode国际青少年编程竞赛- Python-2级训练场-识别循环规律2 1、 for i in range(3):Dev.step(3)Dev.turnRight()Dev.step(4)Dev.turnLeft()2、 for i in range(3):Spaceship.step(3)Spaceship.turnRight()Spaceship.step(1)3、 Dev.turnLeft() Dev.step(Dev.x - Item[1].…...

12.轻量级锁原理及其实战

文章目录 轻量级锁原理及其实战1.轻量级锁的核心原理2.轻量级锁的演示2.1.轻量级锁的演示代码2.2.结果分析 3.轻量级锁的分类3.1.普通自旋锁3.2.自适应自旋锁 4.轻量级锁的膨胀 轻量级锁原理及其实战 引入轻量级锁的主要目的是在多线程环境竞争不激烈的情况下&#xff0c; 通过…...

栈结构(c语言)

1.栈的概念 栈&#xff1a;一种特殊的线性表&#xff0c;其只允许在固定的一端进行插入和删除元素操作。进行数据插入和删除操作的一端称为栈顶&#xff0c;另一端称为栈底。栈中的数据元素遵守后进先出LIFO&#xff08;Last In First Out&#xff09;的原则。 压栈&am…...

【C++】C/C++中新const用法:const成员

欢迎来到CILMY23的博客 本篇主题为&#xff1a; C/C中新const用法&#xff1a;const成员 个人主页&#xff1a;CILMY23-CSDN博客 系列专栏&#xff1a;Python | C | C语言 | 数据结构与算法 | 贪心算法 | Linux 感谢观看&#xff0c;支持的可以给个一键三连&#xff0c;点赞…...

武汉凯迪正大—钢管焊缝裂纹探伤仪

产品概述 武汉凯迪正大无损探伤仪是一种便携式工业无损探伤仪器&#xff0c; 能够快速便捷、无损伤、精确地进行工件内部多种缺陷&#xff08;裂纹、夹杂、气孔等&#xff09;的检测、定位、评估和诊断。既可以用于实验室&#xff0c;也可以用于工程现场。 设置简单&#xff0c…...

为什么 IP 地址通常以 192.168 开头?

在网络配置中&#xff0c;我们经常会遇到以 192.168 开头的 IP 地址&#xff0c;例如 192.168.0.1 或者 192.168.1.100。 这些地址通常用于局域网中&#xff0c;但为什么要选择以 192.168 开头呢&#xff1f; 本文将深入探讨这个问题&#xff0c;并解释其背后的原因和历史渊源…...

elementUi中的el-table合计行添加点击事件

elementUi 文档中&#xff0c;合计行并没有点击事件&#xff0c;这里自己实现了合计行的点击事件。 created() {this.propertyList [{ property: order, label: 序号 },{ property: deptName, label: 单位名称 },{ property: contentPublishQuantity, label: 文章数量 },{ pro…...

Zookeeper集群搭建的一些问题

问题描述一&#xff1a; Cannot open channel to 2 at election address /192.168.60.132:3888解决方案&#xff1a; 查看zookeeper配置文件zoo.cfg / zoo_sample.cfg中集群配置部分 server.1zoo1-net1:2888:3888|zoo1-net2:2889:3889 server.2zoo2-net1:2888:3888|zoo2-net2…...

AI生成Node.js代码的安全隐患与vibecure自动化扫描修复指南

1. 项目概述&#xff1a;AI辅助开发的安全“守门员”如果你最近用Claude、Cursor、Copilot这类AI助手快速搭建了一个Node.js后端&#xff0c;感觉功能跑通了&#xff0c;界面也像模像样&#xff0c;是不是就准备直接部署上线了&#xff1f;先别急。作为一个踩过无数次坑的过来人…...

Ubuntu 20.04 + RTX 4090 保姆级教程:从零搭建BEVFormer训练环境(含避坑指南)

Ubuntu 20.04 RTX 4090 深度指南&#xff1a;高效搭建BEVFormer训练环境 当高性能消费级显卡遇上前沿视觉算法框架&#xff0c;如何在单卡环境下最大化利用硬件资源成为开发者面临的首要挑战。本文将基于RTX 4090的48GB显存特性&#xff0c;系统性地解决BEVFormer环境配置中的…...

如何快速上手BepInEx:面向Unity开发者的终极插件框架指南

如何快速上手BepInEx&#xff1a;面向Unity开发者的终极插件框架指南 【免费下载链接】BepInEx Unity / XNA game patcher and plugin framework 项目地址: https://gitcode.com/GitHub_Trending/be/BepInEx 想要为Unity游戏添加自定义功能&#xff0c;但又不想修改游戏…...

SAP FICO会计凭证附件管理升级:从服务器存储到OpenText集成的完整迁移指南

SAP FICO会计凭证附件管理升级&#xff1a;从本地存储到OpenText集成的全流程实践 当企业财务系统运行五年后&#xff0c;会计凭证附件数量突破百万级时&#xff0c;SAP服务器本地存储的局限性开始集中爆发——存储空间以每月15%的速度消耗&#xff0c;FB03查看附件的响应时间从…...

利用Taotoken的稳定性与路由能力保障线上服务高可用

利用Taotoken的稳定性与路由能力保障线上服务高可用 1. 线上服务中的大模型集成挑战 将大模型API集成到线上生产环境时&#xff0c;开发团队常面临单点故障风险。当依赖单一模型供应商或API端点时&#xff0c;服务中断、配额耗尽或突发流量都可能导致业务不可用。传统解决方案…...

基于RAG与向量搜索的本地语义文件搜索系统构建指南

1. 项目概述&#xff1a;当本地文件库遇上大语言模型如果你和我一样&#xff0c;电脑里塞满了各种文档、笔记、代码片段和PDF报告&#xff0c;每次想找点东西都得靠记忆或者全局搜索碰运气&#xff0c;那你一定理解那种“信息就在那里&#xff0c;但我就是找不到”的无力感。传…...

创业团队如何利用Taotoken统一管理多个AI项目的模型调用与成本

创业团队如何利用Taotoken统一管理多个AI项目的模型调用与成本 1. 多项目模型调用的常见挑战 小型技术团队在同时开发多个AI应用时&#xff0c;通常会遇到三个核心问题。第一是模型供应商分散&#xff0c;不同项目可能使用不同厂商的API&#xff0c;导致密钥管理和调用方式碎…...

杀戮尖塔2手机版下载

《杀戮尖塔2》&#xff08;Slay the Spire 2&#xff09;已于 2026年3月5日 正式开启 PC 端&#xff08;Steam&#xff09;的抢先体验&#xff08;Early Access&#xff09;。针对你关注的手机版及相关信息&#xff0c;整理如下&#xff1a; 从夸克网盘下载 1. 作者与开发商 …...

iTVBoxFast二开版深度体验:从用户视角看‘会员系统’与‘多仓聚合’到底香不香?

iTVBoxFast二开版深度体验&#xff1a;会员系统与多仓聚合的实战评测 第一次打开iTVBoxFast二开版时&#xff0c;我正窝在沙发上用遥控器翻找能看的电影。作为长期折腾各类TVBox壳子的老用户&#xff0c;这次吸引我的是两个核心功能&#xff1a;号称"商业化闭环"的会…...

新手入门指南:在快马平台上手写第一个instagram图片下载脚本

今天想和大家分享一个特别适合编程新手的小项目&#xff1a;用Python写一个简单的Instagram图片下载脚本。这个项目不仅能帮助我们理解网络爬虫的基本原理&#xff0c;还能学到文件操作和异常处理等实用技巧。最关键的是&#xff0c;整个过程在InsCode(快马)平台上操作特别方便…...