WPF上下滚动字幕
XAML代码:
<local:WorkSpaceContent x:Class="SunCreate.CombatPlatform.Client.NoticeMarquee"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:SunCreate.CombatPlatform.Client;assembly=SunCreate.CombatPlatform.Client"
mc:Ignorable="d"
d:DesignHeight="35" d:DesignWidth="300" Loaded="WorkSpaceContent_Loaded" MouseEnter="WorkSpaceContent_MouseEnter" MouseLeave="WorkSpaceContent_MouseLeave">
<local:WorkSpaceContent.Resources>
<ControlTemplate x:Key="btnTemplate" TargetType="Button">
<TextBlock Name="txt" Margin="5 0 5 0" Text="{TemplateBinding Content}" FontSize="12" Cursor="Hand" ToolTip="{TemplateBinding ToolTip}" Foreground="#fff" VerticalAlignment="Center"></TextBlock>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter TargetName="txt" Property="Foreground" Value="#ff5e5e"></Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<Storyboard x:Key="storyboard">
<DoubleAnimation Duration="0:0:1" To="25" Storyboard.TargetName="stackPanel" Storyboard.TargetProperty="RenderTransform.Y"/>
</Storyboard>
</local:WorkSpaceContent.Resources>
<Grid Background="#00a6da">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="60"></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock Margin="15 0 5 0" Text="公告:" FontSize="12" Foreground="#ffff33" VerticalAlignment="Center"></TextBlock>
<ScrollViewer Grid.Column="1" Name="scrollViewer" HorizontalScrollBarVisibility="Hidden"
HorizontalContentAlignment="Stretch"
VerticalScrollBarVisibility="Hidden"
VerticalContentAlignment="Stretch" Height="25">
<Border Height="25" >
<StackPanel x:Name="stackPanel" Margin="0 -25 0 0" >
<StackPanel.RenderTransform>
<TranslateTransform />
</StackPanel.RenderTransform>
<Button Name="btn1" Height="25" Click="btn_Click" Template="{StaticResource btnTemplate}"></Button>
<Button Name="btn2" Height="25" Click="btn_Click" Template="{StaticResource btnTemplate}"></Button>
<Button Name="btn3" Height="25" Click="btn_Click" Template="{StaticResource btnTemplate}"></Button>
</StackPanel>
</Border>
</ScrollViewer>
</Grid>
</local:WorkSpaceContent>
后台代码:
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
{
/// <summary>
/// 公告滚动显示
/// </summary>
public partial class NoticeMarquee : WorkSpaceContent
{
private System.Timers.Timer _timer;
private List<TES_NOTICE> _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 = ;
_data = HI.Get<INoticeService>().GetListPage(null, DateTime.MinValue, DateTime.Now, , , ref total).ToList();
_data.Reverse();
_index = _data.Count - ;
Dispatcher.BeginInvoke(new Action(() =>
{
stackPanel.RenderTransform = new TranslateTransform(, );
}));
ShowData();
Thread.Sleep( * );
}
}); _timer = new System.Timers.Timer();
_timer.Interval = ;
_timer.Elapsed += Action;
_timer.Start();
}
} private void Action(object sender, ElapsedEventArgs e)
{
Dispatcher.BeginInvoke(new Action(() =>
{
stackPanel.RenderTransform = new TranslateTransform(, );
_storyboard.Begin();
})); _index--;
if (_index < )
{
_index = _data.Count - ;
} ShowData();
} private void ShowData()
{
Dispatcher.BeginInvoke(new Action(() =>
{
TES_NOTICE data1 = GetData(_index, );
TES_NOTICE data2 = GetData(_index, );
TES_NOTICE data3 = GetData(_index, ); 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 - )
{
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上下滚动字幕的更多相关文章
- HTML滚动字幕代码参数详解及Js间隔滚动代码
html文字滚动代码 <marquee style="WIDTH: 388px; HEIGHT: 200px" scrollamount="2" dire ...
- UILabel滚动字幕的实现
经常需要在应用中显示一段很长的文字,比如天气或者广告等,这时候使用滚动字幕的方式比较方便. 参考文献: [1] YouXianMing, 使用UILabel实现滚动字幕移动效果, 博客园 [2] ht ...
- js原生 + jQuery实现页面滚动字幕
js原生/jQuery实现页面滚动字幕效果 17:45:49 在新闻列表或者文章列表信息等页面中很容易要求实现字幕滚动的效果,以下为简单的实现页面中滚动字幕的效果 1.jQuery实现页面滚动字幕效果 ...
- C#-循环滚动字幕,timer,从左至右,从右至左,暂停---ShinePans
Lable的Left属性是能够更改的,可是 Right属性不能够更改,所以我们能够利用 这个特点做自加 自减运算 using System; using System.Collections.Gene ...
- DS控件库 DSLed控件呈现滚动字幕效果
滚动字幕效果在DSled上可以使用偏移来实现,代码如下 运行效果
- WPF数字滚动效果
和WPF数字滚动抽奖有区别,WPF数字滚动抽奖是随机的,而这里是确定的. 为了系统演示,这个效果通宵加班写了整整6个小时,中间就上了次厕所. 代码: RollingNumberItemCtrl.xam ...
- 【Cocos2dx 3.3 Lua】滚动字幕
参考资料: http://blog.csdn.net/jackystudio/article/details/12991977 1.原理 通过调用update来更新位置达到 ...
- Flash和滚动字幕
flash 1.插入flash 1)<object> <embed src="路径"></embed> ...
- 使用UILabel实现滚动字幕移动效果
使用UILabel实现滚动字幕移动效果 这个链接中的代码也实现了这种效果 https://github.com/cbpowell/MarqueeLabel 最终效果如下: 原理如下: 1. 获取文本 ...
随机推荐
- netbeans php环境搭建
jdk必须: sudo apt-get install openjdk-7-jdk
- VS Code设置中文和配置Python环境
前言: Visual Studio Code(以下简称VSCode)是一个轻量且强大的代码编辑器,支持Windows,OS X和Linux.内置JavaScript.TypeScript和Node.j ...
- 在VMware Workstation中安装Ubuntu Server 16.04.5图解教程
最近要在Ubuntu中部署openstack,为了节省空间和内存,最终选择了Ubuntu服务器.看了很多前辈和大佬的安装教程,在这里记录一下我自己的Ubuntu Server 16.04.5的安装过程 ...
- Selenium+TestNG+Maven 搭建
Java环境配置 Eclipse配置TestNG Eclipse配置Maven pom.xml文件相关配置,添加依赖selenium和TestNg的jar包 <!-- https://mvnre ...
- 格式化程序尝试对消息反序列化时引发异常: 尝试对参数 http://tempuri.org/ 进行反序列化时出错: GetLzdtArticleResult。InnerException 消息是“反序列化对象 属于类型 lzdt.DTO.Dtolzdt[] 时出现错误。读取 XML 数据时,超出最大
当遇到这个错误的时候郁闷了好长时间报错是字符串长度过大可是修改了MaxStringContentLength”属性的值却不起作用最后才发现还是因为配置文件配置的问题在服务端 格式化程序尝试对消息反序列 ...
- Python深度学习之安装theano(windows)
前方预警:windows的坑太多了,抛弃用linux吧 安装theano,提前清空自己的python环境吧,坑太多了,anaconda会自动安装path 一,首先安装python包管理anaconda ...
- Text Relatives
[Text Relatives] With TextKit the resources at your disposal range from framework objects—such as te ...
- select for update [nowait]
Syntax The NOWAIT and WAIT clauses let you tell the database how to proceed if the SELECT statement ...
- Ian Goodfellow——对抗神经网络之父
争议.流派,有关GAN的一切:Ian Goodfellow Q&A:https://baijiahao.baidu.com/s?id=1595081179447191755&wfr=s ...
- Grails入门系列(一)
Grails入门系列(一) JAVAweb开发技术相对于php,python,note.js等新式技术更为复杂,向来以繁杂的配置著称,但是Java任然被广泛的应用于大型企业级的项目,主要是因为技术成熟 ...