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.pswp.cn/diannao/77321.shtml
繁體地址,請注明出處:http://hk.pswp.cn/diannao/77321.shtml
英文地址,請注明出處:http://en.pswp.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;的原則。其結構可以參考羽毛…