WPF轮播图动画交互 动画缩放展示图片

WPF轮播图动画交互 动画缩放展示图片

  • 效果如下图:
    请添加图片描述
    XAML代码:
<Window x:Class="Caroursel.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:local="clr-namespace:Caroursel"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"Title="MainWindow"Width="1000"Height="450"mc:Ignorable="d"><Window.Resources><Style x:Key="MaskGrid" TargetType="Grid"><Setter Property="Background" Value="#5B000000" /><Style.Triggers><Trigger Property="IsMouseOver" Value="True"><Trigger.EnterActions><BeginStoryboard><Storyboard><DoubleAnimation Storyboard.TargetProperty="Opacity" To="0" Duration="0:0:0.2" /></Storyboard></BeginStoryboard></Trigger.EnterActions><Trigger.ExitActions><BeginStoryboard><Storyboard><DoubleAnimation Storyboard.TargetProperty="Opacity" To="1" Duration="0:0:0.2" /></Storyboard></BeginStoryboard></Trigger.ExitActions></Trigger></Style.Triggers></Style><Style x:Key="ContainerGrid" TargetType="Grid"><EventSetter Event="MouseEnter" Handler="Grid_MouseEnter" /><EventSetter Event="MouseLeave" Handler="Grid_MouseLeave" /></Style><Style TargetType="TextBlock"><Setter Property="FontSize" Value="18" /><Setter Property="FontWeight" Value="Bold" /><Setter Property="Foreground" Value="White" /><Setter Property="TextWrapping" Value="Wrap" /><Setter Property="Width" Value="18" /><Setter Property="VerticalAlignment" Value="Center" /><Setter Property="HorizontalAlignment" Value="Center" /></Style></Window.Resources><Grid><Grid.ColumnDefinitions><ColumnDefinition Width="Auto" /><ColumnDefinition Width="Auto" /><ColumnDefinition Width="Auto" /><ColumnDefinition Width="Auto" /><ColumnDefinition Width="Auto" /></Grid.ColumnDefinitions><Grid x:Name="Grid1"Grid.Column="0"Width="200"Style="{StaticResource ContainerGrid}"><Image HorizontalAlignment="Center"VerticalAlignment="Center"Source="1.jpg"Stretch="UniformToFill" /><Grid Style="{StaticResource MaskGrid}"><TextBlock Text="迅捷斥候" /></Grid></Grid><Grid x:Name="Grid2"Grid.Column="1"Width="200"Style="{StaticResource ContainerGrid}"><Image HorizontalAlignment="Center"VerticalAlignment="Center"Source="2.jpg"Stretch="UniformToFill" /><Grid Style="{StaticResource MaskGrid}"><TextBlock Text="黑暗之女" /></Grid></Grid><Grid x:Name="Grid3"Grid.Column="2"Width="200"Style="{StaticResource ContainerGrid}"><Image HorizontalAlignment="Center"VerticalAlignment="Center"Source="3.jpg"Stretch="UniformToFill" /><Grid Style="{StaticResource MaskGrid}"><TextBlock Text="刀锋舞者" /></Grid></Grid><Grid x:Name="Grid4"Grid.Column="3"Width="200"Style="{StaticResource ContainerGrid}"><Image HorizontalAlignment="Center"VerticalAlignment="Center"Source="4.jpg"Stretch="UniformToFill" /><Grid Style="{StaticResource MaskGrid}"><TextBlock Text="诡术妖姬" /></Grid></Grid><Grid x:Name="Grid5"Grid.Column="4"Width="200"Style="{StaticResource ContainerGrid}"><Image HorizontalAlignment="Right"VerticalAlignment="Center"Source="5.jpg"Stretch="UniformToFill" /><Grid Style="{StaticResource MaskGrid}"><TextBlock Text="潮汐海灵" /></Grid></Grid></Grid>
</Window>

C#代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;namespace Caroursel
{/// <summary>/// MainWindow.xaml 的交互逻辑/// </summary>public partial class MainWindow : Window{public MainWindow(){InitializeComponent();SizeChanged += MainWindow_SizeChanged;}private void MainWindow_SizeChanged(object sender, SizeChangedEventArgs e){var targetWidth = Width / 5;DoubleAnimation da = new DoubleAnimation(targetWidth, new Duration(TimeSpan.FromSeconds(0.25)));Grid1.BeginAnimation(WidthProperty, da);Grid2.BeginAnimation(WidthProperty, da);Grid3.BeginAnimation(WidthProperty, da);Grid4.BeginAnimation(WidthProperty, da);Grid5.BeginAnimation(WidthProperty, da);}private void Grid_MouseEnter(object sender, MouseEventArgs e){var grid = sender as Grid;var targetWidth = Width / 5 * 3;DoubleAnimation da = new DoubleAnimation(targetWidth, new Duration(TimeSpan.FromSeconds(0.3)));da.EasingFunction = new CubicEase() { EasingMode = EasingMode.EaseOut };grid.BeginAnimation(WidthProperty, da);var remainingWidth = Width - targetWidth;targetWidth = remainingWidth / 4;da = new DoubleAnimation(targetWidth, new Duration(TimeSpan.FromSeconds(0.25)));if (grid != Grid1){Grid1.BeginAnimation(WidthProperty, da);}if (grid != Grid2){Grid2.BeginAnimation(WidthProperty, da);}if (grid != Grid3){Grid3.BeginAnimation(WidthProperty, da);}if (grid != Grid4){Grid4.BeginAnimation(WidthProperty, da);}if (grid != Grid5){Grid5.BeginAnimation(WidthProperty, da);}}private void Grid_MouseLeave(object sender, MouseEventArgs e){var targetWidth = Width / 5;DoubleAnimation da = new DoubleAnimation(targetWidth, new Duration(TimeSpan.FromSeconds(0.25)));Grid1.BeginAnimation(WidthProperty, da);Grid2.BeginAnimation(WidthProperty, da);Grid3.BeginAnimation(WidthProperty, da);Grid4.BeginAnimation(WidthProperty, da);Grid5.BeginAnimation(WidthProperty, da);}}
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/diannao/77321.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

为什么 npm list -g 没显示 node_modules?✨

揭秘&#xff1a;为什么 npm list -g 没显示 node_modules&#xff1f;&#x1f575;️‍♂️✨ 嗨&#xff0c;各位代码探险家&#xff01;&#x1f44b; 今天我们要破解一个 npm 小谜团&#xff1a;运行 npm list -g --depth0 时&#xff0c;为什么输出的路径里看不到 node_…

都江堰与郑国渠

目录标题 一、历史背景&#xff1a;地缘博弈下的水利突围都江堰&#xff1a;化水患为天府的千年大计郑国渠&#xff1a;间谍引发的战略反转 二、工程智慧&#xff1a;超越时代的科技奇迹都江堰&#xff1a;生态治水的典范郑国渠&#xff1a;泥沙资源化的创举 三、后世影响&…

链路聚合+vrrp

1.链路聚合 作用注意事项将多个物理接口&#xff08;线路&#xff09;逻辑上绑定在一起形成一条逻辑链路&#xff0c;起到叠加带宽的作用1.聚合接口必须转发速率一致。2.聚合设备两端必须一致 配置命令 方法一 [Huawei]interface Eth-Trunk 0----先创建聚合接口&#xff0c;…

【STM32单片机】#7 定时器输入捕获

主要参考学习资料&#xff1a; B站江协科技 STM32入门教程-2023版 细致讲解 中文字幕 开发资料下载链接&#xff1a;https://pan.baidu.com/s/1h_UjuQKDX9IpP-U1Effbsw?pwddspb 单片机套装&#xff1a;STM32F103C8T6开发板单片机C6T6核心板 实验板最小系统板套件科协 实验&…

【android bluetooth 框架分析 01】【关键线程 3】【bt_jni_thread 线程介绍】

1. bt_jni_thread 职责介绍 bt_jni_thread 这个线程的作用是专门负责处理蓝牙 JNI 层的消息循环&#xff0c;也可以说是 C 层和 Java 层交互的桥梁线程。 1.1 什么是 JNI 层&#xff1f;为什么需要这个线程&#xff1f; JNI&#xff08;Java Native Interface&#xff09;是 …

基于视觉语言模型的机器人实时探索系统!ClipRover:移动机器人零样本视觉语言探索和目标发现

作者&#xff1a;Yuxuan Zhang 1 ^{1} 1, Adnan Abdullah 2 ^{2} 2, Sanjeev J. Koppal 3 ^{3} 3, and Md Jahidul Islam 4 ^{4} 4单位&#xff1a; 2 , 4 ^{2,4} 2,4佛罗里达大学电气与计算机工程系RoboPI实验室&#xff0c; 1 , 3 ^{1,3} 1,3佛罗里达大学电气与计算机工程系F…

SpringBoot和微服务学习记录Day2

微服务 微服务将单体应用分割成更小的的独立服务&#xff0c;部署在不同的服务器上。服务间的关联通过暴露的api接口来实现 优点&#xff1a;高内聚低耦合&#xff0c;一个模块有问题不影响整个应用&#xff0c;增加可靠性&#xff0c;更新技术方便 缺点&#xff1a;增加运维…

网站集群批量管理-Ansible剧本与变量

复盘内容&#xff1a;链接指北 查看ansible命令文档 ansible-doc -s systemd一、剧本 何为剧本: playbook 文件,用于长久保存并且实现批量管理,维护,部署的文件. 类似于脚本存放命令和变量 剧本yaml格式,yaml格式的文件:空格,冒号. 剧本未来我们批量管理,运维必会的内容. …

如何在Dify中安装运行pandas、numpy库(离线、在线均支持,可提供远程指导)

pandas和numpy这两个库是数据科学和数据分析中经常使用的工具包&#xff0c;原生的Dify无法直接使用这两个库&#xff0c;需要手动安装后才可以使用。本文将介绍如何在Dify中安装pandas和numpy&#xff0c;并在代码执行节点中运行使用pandas和numpy。 Dify的代码执行节点中的py…

Helm核心概念与常见操作介绍

在管理Kubernetes集群里的应用时&#xff0c;Helm能帮上大忙&#xff0c;它把应用的部署、升级和管理变得简单多了&#xff0c;有如是Kubernetes的 “应用商店”。 Helm的三个重要概念 三大概念最直接的理解&#xff1a;Helm 安装 charts 到 Kubernetes 集群中&#xff0c;每…

rkmpp 解码 精简mpi_dec_test.c例程

rkmpp 解码流程&#xff08;除 MPP_VIDEO_CodingMJPEG 之外&#xff09; 源码 输入h264码流 输出nv12文件 /** Copyright 2015 Rockchip Electronics Co. LTD** Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file exce…

用一个实际例子快速理解MCP应用的工作步骤

已经有很多的文章介绍MCP server&#xff0c;MCP Client工作原理&#xff0c;这里不做太多介绍。但是很多介绍都只是侧重介绍概念&#xff0c;实际的工作原理理解起来对初学者还是不太友好。本文以一个智能旅游咨询系统为例&#xff0c;详细说明在利用 Model Context Protocol&…

【LeetCode 题解】数据库:1321.餐馆营业额变化增长

一、问题描述 本题给定了一个名为 Customer 的表&#xff0c;记录了餐馆顾客的交易数据&#xff0c;包括顾客 ID、姓名、访问日期和消费金额。作为餐馆老板&#xff0c;我们的任务是分析营业额的变化增长情况&#xff0c;具体来说&#xff0c;就是计算以 7 天&#xff08;某日…

【Python】读取xlsb或xlsx的单一或连续单元格工具类

代码主要来自Kimi.ai&#xff0c;有修改。 优先使用工作表序号索引工作表&#xff0c;序号从1开始。 运行需要先安装openpyxl和pyxlsb两个第三方库。 import openpyxl from openpyxl.utils import range_boundaries from pyxlsb import open_workbook as open_xlsbclass Exc…

【蓝桥杯】动态规划:背包问题

这篇文章主要记录动态规划方面的学习。 动态规划的核心思想: 把大问题分解成小问题,记住小问题的解,避免重复计算。 动态规划(DP)的三大特点: ①最优子结构:大问题的最优解可以由小问题的最优解推导出来 ②重叠子问题:在求解过程中会反复遇到相同的小问题 ③无后效…

华为数字芯片机考2025合集1已校正

单选 1&#xff0e;以下低功耗措施中&#xff0c;哪种不是降低电路翻转率的方法? A.在不进行算术运算的时候&#xff0c;使这些模块的输入保持不变&#xff0c;不让新的操作数进来 B.采用Gray 码或One‐hot 码作为状态机编码 C.减少电路中的glitch D.重新安排“if‐else”表达…

React 列表渲染

开发环境&#xff1a;Reacttsantd 你可能经常需要通过 JavaScript 的数组方法 来操作数组中的数据&#xff0c;从而将一个数据集渲染成多个相似的组件。在这篇文章中&#xff0c;你将学会如何在 React 中使用 filter() 筛选需要渲染的组件和使用 map() 把数组转换成组件数组。 …

力扣刷题DAY11(动态规划-线性DP)

一、最长上升子序列 300. 最长递增子序列 &#xff08;一&#xff09;初版代码 class Solution { public:int lengthOfLIS(vector<int>& nums) {int n nums.size();vector<int> f(n 1, 1); //初始化为1&#xff0c;因为每个数至少可以作为一个单独的序列in…

DFS--

数字的全排列 #include <bits/stdc.h> using namespace std;//最大的排列数目 const int N10; int n; //存储排列的路径 int path[N]; //标记数字是否已经被使用 bool st[N];void dfs(int u){//到达递归边界&#xff0c;输出一个排列if(un){//输出循环for(int i0; i<…

栈与队列及其基础应用

一.栈 1.栈的定义 栈是一种特殊的线性表&#xff0c;其只允许在固定的一端进行插入和删除元素操作。进行数据插入和删除操作的一端称为栈顶&#xff0c;另一端称为栈底。栈中的数据元素遵守后进先出LIFO&#xff08;Last In First Out&#xff09;的原则。其结构可以参考羽毛…