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. 课程预告丨12月15日官方直播带你领略ArkUI的声明式开发范式之美

    方舟开发框架(ArkUI)的声明式开发范式有什么优势?Java/JS/eTS(extended TypeScript)三种语言,用哪种语言更好? 12月15日 19:00-20:30,Hello Ha ...

  2. iOS系统崩溃的捕获

    iOS系统崩溃的捕获 相信大家在开发iOS程序的时候肯定写过各种Bug,而其中最为严重的Bug就是会导致崩溃的Bug(一般来说妥妥的P1级).在应用软件大大小小的各种异常中,崩溃确实是最让人难以接受的 ...

  3. 重新整理.net core 计1400篇[五] (.net core 修改为Startup模式 )

    前言 随着不断的升级改版,我们离dotnet帮我们生成的文件中还差一步,那就是我们少了一个Startup,那么这个有什么用呢?让我们来补上it吧. 在此之前需要明白一件事,那就是Startup是一种约 ...

  4. Django3.0连接数据库注意点

    需先在应用下的__Init__.py文件中配置 import pymysqlpymysql.version_info=(1, 3, 13, 'final', 0) # 3.0时需要pymysql.in ...

  5. 基于 Mesh 的统一路由在海外业务的实践

    ​简介:本文主要介绍我们最近在利用 Service Mesh 架构解决海外业务问题中一些实践和价值探索.我们在海外业务引入 Mesh 架构过程中,充分利用 Istio 的基于 yaml 来描述和定义路 ...

  6. 探秘RocketMQ源码——Series1:Producer视角看事务消息

    简介: 探秘RocketMQ源码--Series1:Producer视角看事务消息 1. 前言 Apache RocketMQ作为广为人知的开源消息中间件,诞生于阿里巴巴,于2016年捐赠给了Apac ...

  7. 为什么Spring仍然会是云原生时代最佳平台之一?

    简介: 基于Java语言的Spring生态,还能否适应新的开发方式,比如Cloud Native.Serverless.Faas等,它还会是云原生时代的最佳平台的选择吗?本文将从5个角度来为你分析一下 ...

  8. 基于 MaxCompute 的智能推荐解决方案

    简介: 在互联网行业红利已过.在获客成本越来越高.在用户在线时长全网基本无增长以及信息大爆炸的情况下,如何更好的转化新用户和提升老用户粘性就变得至关重要,智能化的个性化推荐无疑是经过验证的重要手段之一 ...

  9. [ML] 通过llama.cpp与羊驼聊天的网页界面- 详解 Serge 的启动使用

      Serge 虽然能够让我们在笔记本上跑起来 7B模型, 但实际运行非常消耗CPU,对话生成响应非常非常慢. 1. 官方指导是使用如下命令直接运行: $ docker run -d -v weigh ...

  10. WPF 使用 Skia 解析绘制 SVG 图片

    本文告诉大家如何在 WPF 里面,使用 Skia 解析绘制 SVG 图片.本文也适合控制台使用 SkiaSharp 解析绘制 SVG 图片,本文的 WPF 部分只是在 Skia 绘制完成之后,将 Sk ...