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 ...
随机推荐
- mysql 必知必会整理—sql 通配符[四]
前言 简单介绍一下sql 高级过滤. 正文 首先简单介绍一下通配符,用来匹配值的一部分的特殊字符. 搜索模式(search pattern)① 由字面值.通配符或两者组合构成的搜索条件. 前面介绍操作 ...
- css 中的BFC
一.是什么 我们在页面布局的时候,经常出现以下情况: 这个元素高度怎么没了? 这两栏布局怎么没法自适应? 这两个元素的间距怎么有点奇怪的样子? ...... 归根究底是元素之间相互的影响,导致了意料之 ...
- textfsm 案例分享
由于安全需要,需要定期对接入层交换机配置进行合规检查,避免不规范配置存在的漏洞给公司网络带来安全风险. 如下案例是通过textfsm 提取交换机接口的配置信息,进一步进行检查准入配置是否开启: 1.首 ...
- 开源微服务编排框架:Netflix Conductor
简介:本文主要介绍netflix conductor的基本概念和主要运行机制. 作者 | 夜阳 来源 | 阿里技术公众号 本文主要介绍netflix conductor的基本概念和主要运行机制. ...
- [GPT] 机器学习框架平台或框架的学习成本和友好程度排名?
按照学习成本从高到低的顺序,大概如下: TensorFlow:虽然TensorFlow功能强大,但学习曲线比较陡峭,需要掌握一些深度学习的基本概念和数学知识. PyTorch:PyTorch相对而 ...
- Ingress-Controller高可用方案及多租户场景(21)
一.Ingress-controller高可用 Ingress Controller 是集群流量的接入层,对它做高可用非常重要,可以基于 keepalive 实现 nginx-ingress-cont ...
- Linux 根文件系统的移植(从入门到精通)
一.简介 提到操作系统的安装,还得从大学的时候说起,刚入学的时,朋友的系统本崩了,跑去电脑城换个系统花了40大洋,震惊了贫穷的我.好像发现了商机,果断开始了折腾自己的电脑,然后用朋友的电脑进行测试,由 ...
- 习题8 #第8章 Verilog有限状态机设计-4 #Verilog #Quartus #modelsim
4. 用状态机设计交通灯控制器,设计要求:A路和B路,每路都有红.黄.绿三种灯,持续时间为:红灯45s,黄灯5s,绿灯40秒. A路和B路灯的状态转换是: (1) A红,B绿(持续时间40s): (2 ...
- 一文搞懂drag&drop浏览器拖放功能的实现
拖放功能,即将一个元素从一个区域,通过拖拽,放置到另一个区域.常见的应用是将文件或图片从一个区域,拖放到另一个区域.中文常常把这表述成拖拽,实际上拖拽的描述并不准确,应该叫拖放,因为drag事件和dr ...
- Selenium使用总结:加载Flash、禁用JS、滚动页面至元素、缩放页面
前言 前几周做了个使用Selenium的项目,踩了好多好多好多的Selenium的坑,越来越感觉他作为一个第三方库,对于Chrome的操作实在是有局限.另外,推荐大家一个Selenium之外的操作浏览 ...