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实现轮播图的更多相关文章

  1. js 基础篇(点击事件轮播图的实现)

    轮播图在以后的应用中还是比较常见的,不需要多少行代码就能实现.但是在只掌握了js基础知识的情况下,怎么来用较少的而且逻辑又简单的方法来实现呢?下面来分析下几种不同的做法: 1.利用位移的方法来实现 首 ...

  2. 实现下来ScrollView放大轮播图

    创建工程,创建一个UIScrollView属性,并遵循其协议: #define kWidth self.view.frame.size.width//屏幕宽 #define kHeight self. ...

  3. ViewPager轮播图

    LoopViewPagerLayout无限轮播 项目地址:https://github.com/why168/LoopViewPagerLayout 支持三种动画: 支持修改轮播的速度: 支持修改滑动 ...

  4. CSS-用伪类制作小箭头(轮播图的左右切换btn)

    先上学习地址:http://www.htmleaf.com/Demo/201610234136.html 作者对轮播图左右按钮的处理方法一改往常,不是简单地用btn.prev+btn.next的图片代 ...

  5. phpcms首页实现轮播图

    1.在你想要加轮播图的位置加入以下 <div id="flowDiagram" > <div id="button"> <span ...

  6. React视角下的轮播图

    天猫购物网站最显眼的就是轮播图了.我在学习一样新js库,一个新框架或新的编程思想的时候,总是感叹"入门必做选项卡,进阶须撸轮播图."作为一个React组件,它是状态操控行为的典型, ...

  7. Jquery 轮播图简易框架

    =====================基本结构===================== <div class="carousel" style="width: ...

  8. 原生js焦点轮播图

    原生js焦点轮播图主要注意这几点: 1.前后按钮实现切换,同时注意辅助图2.中间的button随着前后按钮对应切换,同时按button也能跳转到相应的index3.间隔调用与无限轮播.4.注意在动画时 ...

  9. superSlider实现美女轮播图

    superSlider实现美女轮播图 <!DOCTYPE html><html lang="en"><head><meta charset ...

  10. js原生代码实现轮播图案例

    一.轮播图是现在网站网页上最常见的效果之一,对于轮播图的功能,要求不同,效果也不同! 我们见过很多通过不同的方式,实现这一效果,但是有很多比较麻烦,而且不容易理解,兼容性也不好. 在这里分享一下,用j ...

随机推荐

  1. 【转】Java程序员常用工具类库 - 目录

    原文地址:http://rensanning.iteye.com/blog/1553076 有人说当你开始学习Java的时候,你就走上了一条不归路,在Java世界里,包罗万象,从J2SE,J2ME,J ...

  2. vue中执行异步函数async和await的用法

    在开发中,可能会遇到两个或多个函数异步执行的情况,对于Vue中函数的异步函数执行做了一个小总结,如下: 异步执行使用async和await完成 created() { this.init() }, m ...

  3. MyBatis 核心配置讲解(上)

    大家好,我是王有志,一个分享硬核 Java 技术的互金摸鱼侠. 前两篇的文章中我们分别介绍了 MyBatis 和 MyBaits 的应用组成,到这里基础篇的内容就结束了. 从今天开始,我们正式进入 M ...

  4. var ,let和const三者之间的区别

    var 声明变量可以被修改,可以被重复声明.有变量提升(写的位置和使用时候的位置不一样). let声明变量可以被修改,,但不能重复声明.如文件中有一个let a = 0;后面就不能在定义let a=* ...

  5. 使用 Docker 部署 TailChat 开源即时通讯平台

    1)介绍 TailChat 官网: https://tailchat.msgbyte.com/ 作者:https://www.moonrailgun.com/about/ GitHub : https ...

  6. Serverless 可观测性的过去、现在与未来

    简介: 函数计算可观测性经历了 1.0 -> 2.0 的发展,从闭门造车的可观测发展成开源的可观测,从平台的可观测发展为开发者的可观测,从FaaS Only 的可观测演进成了云原生的可观测. 作 ...

  7. [FAQ] Laravel 验证未通过 Route [login] not defined 处理

    一种方式是在路由中定义一个name为 login 的请求. Route::get('xxx', [XxxController::class, 'x'])->name('login'); 第二种方 ...

  8. WPF 通过 GetMessageExtraInfo 方法获取当前收到的鼠标消息是否由触摸转换过来

    本文将告诉大家如何在 WPF 或者其他 Win32 应用里面,在收到鼠标消息时,通过 GetMessageExtraInfo 方法获取当前收到的鼠标消息是否由触摸消息提升而来 大家都知道,在不开启 W ...

  9. dotnet OpenXML 解析 PPT 里表格的样式

    在 PPT 里面的表格可以通过表格样式配置决定表格的样式,本文将和大家介绍如何获取和解析表格的样式 本文属于 OpenXML 系列博客,有一定的上下文,详细请参阅 Office 使用 OpenXML ...

  10. pde复习笔记 第一章 波动方程 第六节 能量不等式、波动方程解的唯一性和稳定性

    能量不等式 这一部分需要知道的是能量的表达式 \[E(t)=\int_{0}^{l}u_{t}^{2}+a^{2}u_{x}^{2} dx \] 一般而言题目常见的问法是证明能量是减少的,也就是我们需 ...