RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
WPF如何实现上下滚动字幕效果

这篇文章主要介绍了WPF如何实现上下滚动字幕效果,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。

专注于为中小企业提供成都网站制作、成都网站设计服务,电脑端+手机端+微信端的三站合一,更高效的管理,为中小企业兴庆免费做网站提供优质的服务。我们立足成都,凝聚了一批互联网行业人才,有力地推动了超过千家企业的稳健成长,帮助中小企业通过网站建设实现规模扩充和转变。

XAML代码:


 
 
  
  
  
   
  
  
 
 
  
 
 
 
 
  
  
 
 
 
  
  
   
   
   
   
   
   
  
  
 
 

后台代码:

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();
 }
 }
}

效果图:

WPF如何实现上下滚动字幕效果

感谢你能够认真阅读完这篇文章,希望小编分享的“WPF如何实现上下滚动字幕效果”这篇文章对大家有帮助,同时也希望大家多多支持创新互联,关注创新互联行业资讯频道,更多相关知识等着你来学习!


标题名称:WPF如何实现上下滚动字幕效果
当前网址:http://scyingshan.cn/article/gcheeo.html