博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
WPF上下滚动字幕
阅读量:6610 次
发布时间:2019-06-24

本文共 5125 字,大约阅读时间需要 17 分钟。

XAML代码:

View Code

后台代码:

using SunCreate.CombatPlatform.Domain;using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading;using System.Timers;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 SunCreate.CombatPlatform.Client{    ///     /// 公告滚动显示    ///     public partial class NoticeMarquee : WorkSpaceContent    {        private System.Timers.Timer _timer;        private List
_data; private int _index; private Storyboard _storyboard; public NoticeMarquee() { InitializeComponent(); } private void WorkSpaceContent_Loaded(object sender, RoutedEventArgs e) { if (_timer == null) { _storyboard = (Storyboard)this.FindResource("storyboard"); System.Threading.Tasks.Task.Factory.StartNew(() => { while (true) { int total = 0; _data = HI.Get
().GetListPage(null, DateTime.MinValue, DateTime.Now, 1, 3, ref total).ToList(); _data.Reverse(); _index = _data.Count - 1; Dispatcher.BeginInvoke(new Action(() => { stackPanel.RenderTransform = new TranslateTransform(0, 25); })); ShowData(); Thread.Sleep(60 * 1000); } }); _timer = new System.Timers.Timer(); _timer.Interval = 5000; _timer.Elapsed += Action; _timer.Start(); } } private void Action(object sender, ElapsedEventArgs e) { Dispatcher.BeginInvoke(new Action(() => { stackPanel.RenderTransform = new TranslateTransform(0, 0); _storyboard.Begin(); })); _index--; if (_index < 0) { _index = _data.Count - 1; } ShowData(); } private void ShowData() { Dispatcher.BeginInvoke(new Action(() => { TES_NOTICE data1 = GetData(_index, 0); TES_NOTICE data2 = GetData(_index, 1); TES_NOTICE data3 = GetData(_index, 2); if (data1 != null) { btn1.Content = data1.NOTICE_CONTENT.Trim().Replace("\r\n", string.Empty); btn1.CommandParameter = data1.ID; btn1.ToolTip = data1.NOTICE_CONTENT; } if (data2 != null) { btn2.Content = data2.NOTICE_CONTENT.Trim().Replace("\r\n", string.Empty); btn2.CommandParameter = data2.ID; btn2.ToolTip = data2.NOTICE_CONTENT; } if (data3 != null) { btn3.Content = data3.NOTICE_CONTENT.Trim().Replace("\r\n", string.Empty); btn3.CommandParameter = data3.ID; btn3.ToolTip = data3.NOTICE_CONTENT; } })); } private TES_NOTICE GetData(int index, int n) { if (_data != null) { int i = index + n; if (i > _data.Count - 1) { i = i % _data.Count; } return _data[i]; } return null; } private void WorkSpaceContent_MouseEnter(object sender, MouseEventArgs e) { _timer.Stop(); } private void WorkSpaceContent_MouseLeave(object sender, MouseEventArgs e) { _timer.Start(); } private void btn_Click(object sender, RoutedEventArgs e) { Button btn = e.Source as Button; string dataId = btn.CommandParameter.ToString(); NoticeView noticeView = new NoticeView(dataId); noticeView.WindowStartupLocation = WindowStartupLocation.CenterScreen; noticeView.ShowDialog(); } }}
View Code

效果图:

 

 

转载于:https://www.cnblogs.com/s0611163/p/7641153.html

你可能感兴趣的文章
Objective-C的setter和getter
查看>>
python数据类型之 元祖、列表字典
查看>>
读周国平作品有感
查看>>
极光消息推送服务器端开发实现推送(上)
查看>>
实现日期比较
查看>>
CMake平台判断
查看>>
NO11 SSH故障排查思路和netstat命令
查看>>
P1060 开心的金明(洛谷,动态规划递推,01背包轻微变形题)
查看>>
逆波兰表达式的递归计算
查看>>
ECMAScript5新特性之isSealed、seal
查看>>
2016-11-15mysql优化笔记
查看>>
R 语文组数据分析 step2
查看>>
【读书笔记】神一样的产品经理(一)
查看>>
后门加密脚本
查看>>
OO第四单元博客总结 - GRAND BATTLE
查看>>
C#委托事件
查看>>
angular的checkbox选中状态判断及获取相应值
查看>>
iOS 开发之头部滚动展示视图
查看>>
Sqlite官方下载对应版本注意细节
查看>>
读书笔记之:鸟哥的Linux私房菜——基础学习篇(第三版) (1-7章)
查看>>