WPF实现轮播图
1、效果图
2、前端代码
<Window x:Class="LiveChartDemo.View.CarouselView"
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:LiveChartDemo.View"
mc:Ignorable="d" Background="Transparent"
Title="CarouselView" Height="380" Width="800">
<Grid Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<StackPanel>
<Image x:Name="CarouselViewImg1" Source="../Img\01.jpg" Stretch="UniformToFill"/>
<!--<Image x:Name="CarouselViewImg1" Source="{Binding ImgUrl}" Stretch="UniformToFill"/>-->
</StackPanel>
<StackPanel Margin="0 310 0 0" Panel.ZIndex="999">
<UniformGrid Columns="5" Background="Transparent" VerticalAlignment="Center" HorizontalAlignment="Center">
<Border Width="15" Height="15" Background="#4FD761" Margin="5" Name="TipButton1" MouseDown="ClickButton" Tag="1"/>
<Border Width="15" Height="15" Background="#F0AF53" Name="TipButton2" MouseDown="ClickButton" Tag="2"/>
<Border Width="15" Height="15" Background="#F0AF53" Name="TipButton3" MouseDown="ClickButton" Tag="3"/>
<Border Width="15" Height="15" Background="#F0AF53" Name="TipButton4" MouseDown="ClickButton" Tag="4"/>
<Border Width="15" Height="15" Background="#F0AF53" Name="TipButton5" MouseDown="ClickButton" Tag="5"/>
</UniformGrid>
</StackPanel>
</Grid>
</Window>
3、后台代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
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.Imaging;
using System.Windows.Shapes;
namespace LiveChartDemo.View
{
/// <summary>
/// CarouselView.xaml 的交互逻辑
/// </summary>
public partial class CarouselView : Window
{
private int step = 0;
public CarouselView()
{
InitializeComponent();
Task.Run(current);
}
private void current()
{
while (true)
{
if (step<5)
{
step++;
}
else
{
step = 1;
}
Thread.Sleep(1000);
Application.Current.Dispatcher.Invoke(() =>
{
CarouselViewImg1.Source = new BitmapImage(new Uri($@"../Img\0{step}.jpg", UriKind.Relative));
Color colorInit = (Color)ColorConverter.ConvertFromString("#F0AF53");
Color colorActive = (Color)ColorConverter.ConvertFromString("#4FD761");
TipButton1.Background = new SolidColorBrush(colorInit);
TipButton2.Background = new SolidColorBrush(colorInit);
TipButton3.Background = new SolidColorBrush(colorInit);
TipButton4.Background = new SolidColorBrush(colorInit);
TipButton5.Background = new SolidColorBrush(colorInit);
switch (step)
{
case 1:
TipButton1.Background = new SolidColorBrush(colorActive);
break;
case 2:
TipButton2.Background = new SolidColorBrush(colorActive);
break;
case 3:
TipButton3.Background = new SolidColorBrush(colorActive);
break;
case 4:
TipButton4.Background = new SolidColorBrush(colorActive);
break;
case 5:
TipButton5.Background = new SolidColorBrush(colorActive);
break;
default:
break;
}
});
}
}
private void ClickButton(object sender, MouseButtonEventArgs e)
{
var tag = (Border)sender;
var Index = tag.Tag.ToString();
Color colorInit = (Color)ColorConverter.ConvertFromString("#F0AF53");
Color colorActive = (Color)ColorConverter.ConvertFromString("#4FD761");
TipButton1.Background = new SolidColorBrush(colorInit);
TipButton2.Background = new SolidColorBrush(colorInit);
TipButton3.Background = new SolidColorBrush(colorInit);
TipButton4.Background = new SolidColorBrush(colorInit);
TipButton5.Background = new SolidColorBrush(colorInit);
step = int.Parse(Index);
switch (step)
{
case 1:
TipButton1.Background = new SolidColorBrush(colorActive);
break;
case 2:
TipButton2.Background = new SolidColorBrush(colorActive);
break;
case 3:
TipButton3.Background = new SolidColorBrush(colorActive);
break;
case 4:
TipButton4.Background = new SolidColorBrush(colorActive);
break;
case 5:
TipButton5.Background = new SolidColorBrush(colorActive);
break;
default:
break;
}
CarouselViewImg1.Source = new BitmapImage(new Uri($@"../Img\0{Index}.jpg", UriKind.Relative));
}
}
}
————————————————
版权声明:本文为CSDN博主「向前走,一直走」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_60013487/article/details/130978267
WPF实现轮播图的更多相关文章
- js 基础篇(点击事件轮播图的实现)
轮播图在以后的应用中还是比较常见的,不需要多少行代码就能实现.但是在只掌握了js基础知识的情况下,怎么来用较少的而且逻辑又简单的方法来实现呢?下面来分析下几种不同的做法: 1.利用位移的方法来实现 首 ...
- 实现下来ScrollView放大轮播图
创建工程,创建一个UIScrollView属性,并遵循其协议: #define kWidth self.view.frame.size.width//屏幕宽 #define kHeight self. ...
- ViewPager轮播图
LoopViewPagerLayout无限轮播 项目地址:https://github.com/why168/LoopViewPagerLayout 支持三种动画: 支持修改轮播的速度: 支持修改滑动 ...
- CSS-用伪类制作小箭头(轮播图的左右切换btn)
先上学习地址:http://www.htmleaf.com/Demo/201610234136.html 作者对轮播图左右按钮的处理方法一改往常,不是简单地用btn.prev+btn.next的图片代 ...
- phpcms首页实现轮播图
1.在你想要加轮播图的位置加入以下 <div id="flowDiagram" > <div id="button"> <span ...
- React视角下的轮播图
天猫购物网站最显眼的就是轮播图了.我在学习一样新js库,一个新框架或新的编程思想的时候,总是感叹"入门必做选项卡,进阶须撸轮播图."作为一个React组件,它是状态操控行为的典型, ...
- Jquery 轮播图简易框架
=====================基本结构===================== <div class="carousel" style="width: ...
- 原生js焦点轮播图
原生js焦点轮播图主要注意这几点: 1.前后按钮实现切换,同时注意辅助图2.中间的button随着前后按钮对应切换,同时按button也能跳转到相应的index3.间隔调用与无限轮播.4.注意在动画时 ...
- superSlider实现美女轮播图
superSlider实现美女轮播图 <!DOCTYPE html><html lang="en"><head><meta charset ...
- js原生代码实现轮播图案例
一.轮播图是现在网站网页上最常见的效果之一,对于轮播图的功能,要求不同,效果也不同! 我们见过很多通过不同的方式,实现这一效果,但是有很多比较麻烦,而且不容易理解,兼容性也不好. 在这里分享一下,用j ...
随机推荐
- Worker 进行多线程任务开发
概念介绍 在 OpenHarmony 中,UI 线程负责处理 UI 事件和用户交互,而 Worker 线程用于处理耗时操作,以提高应用程序的响应速度和用户体验. Worker 线程是与主线程并行的独立 ...
- 【笔记】greatest/least函数&Round函数
刷了一下力扣,发现有很多的函数是自己不清楚的,用了这些函数是比较容易得出结果的,不用自己费心去实现一些奇怪的东西 1.最大最小值 链接:https://leetcode.cn/problems/num ...
- 力扣190(java)-颠倒二进制位(简单)
题目: 颠倒给定的 32 位无符号整数的二进制位. 提示: 请注意,在某些语言(如 Java)中,没有无符号整数类型.在这种情况下,输入和输出都将被指定为有符号整数类型,并且不应影响您的实现,因为无论 ...
- HarmonyOS NEXT应用开发之下拉刷新与上滑加载案例
介绍 本示例介绍使用第三方库的PullToRefresh组件实现列表的下拉刷新数据和上滑加载后续数据. 效果图预览 使用说明 进入页面,下拉列表触发刷新数据事件,等待数据刷新完成. 上滑列表到底部,触 ...
- EventBridge 与 FC 一站式深度集成解析
简介:本篇文章通过对 EventBridge 与 FC 一站式深度集成解析和集成场景的介绍,旨在帮助大家更好的了解面对丰富的事件时,如何使用 EventBridge 与 FC 的一站式集成方案,快速 ...
- 使用率激增 250%,这份报告再次将 Serverless 推向幕前
简介: 本文是对 Datadog 最新的一份 Serverless 报告的解读,欢迎大家留言讨论. 本文是对 Datadog 最新的一份 Serverless 报告的解读,欢迎大家留言讨论. 每项新 ...
- 解读如何安全快速建立IT治理环境
简介:云计算经过十多年的发展,从基础的IAAS,大数据,到各种的PaaS有丰富的产品和生态,非常有效地助力了业务增长和技术创新,并提高了业务的效率.最直观的感受是过去需要几天到一个月的资源交付,现在 ...
- 基于 KubeVela 的 GitOps 交付
简介: KubeVela 是一个简单.易用.且高可扩展的云原生应用管理和交付平台,KubeVela 背后的 OAM 模型天然解决了应用构建过程中对复杂资源的组合.编排等管理问题,同时也将后期的运维策 ...
- CNCF TOC 委员张磊:不断演进的云原生给我们带来了什么?
简介: 任何一种云原生技术,它不再是某种能力的弥补,而是更多地将云的能力以某种方式更简单.更高效地透出给我的应用去使用.无论是容器.K8s 还是 Service Mesh,他们都是在不同的环节帮助应用 ...
- Go 语言网络库 getty 的那些事
简介: Getty 维护团队不追求无意义的 benchmark 数据,不做无意义的炫技式优化,只根据生产环境需求来进行自身改进.只要维护团队在,Getty 稳定性和性能定会越来越优秀. 个人从事互联网 ...