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上下滚动字幕的更多相关文章

  1. HTML滚动字幕代码参数详解及Js间隔滚动代码

    html文字滚动代码 <marquee style="WIDTH: 388px; HEIGHT: 200px" scrollamount="2" dire ...

  2. UILabel滚动字幕的实现

    经常需要在应用中显示一段很长的文字,比如天气或者广告等,这时候使用滚动字幕的方式比较方便. 参考文献: [1] YouXianMing, 使用UILabel实现滚动字幕移动效果, 博客园 [2] ht ...

  3. js原生 + jQuery实现页面滚动字幕

    js原生/jQuery实现页面滚动字幕效果 17:45:49 在新闻列表或者文章列表信息等页面中很容易要求实现字幕滚动的效果,以下为简单的实现页面中滚动字幕的效果 1.jQuery实现页面滚动字幕效果 ...

  4. C#-循环滚动字幕,timer,从左至右,从右至左,暂停---ShinePans

    Lable的Left属性是能够更改的,可是 Right属性不能够更改,所以我们能够利用 这个特点做自加 自减运算 using System; using System.Collections.Gene ...

  5. DS控件库 DSLed控件呈现滚动字幕效果

    滚动字幕效果在DSled上可以使用偏移来实现,代码如下 运行效果

  6. WPF数字滚动效果

    和WPF数字滚动抽奖有区别,WPF数字滚动抽奖是随机的,而这里是确定的. 为了系统演示,这个效果通宵加班写了整整6个小时,中间就上了次厕所. 代码: RollingNumberItemCtrl.xam ...

  7. 【Cocos2dx 3.3 Lua】滚动字幕

    参考资料:     http://blog.csdn.net/jackystudio/article/details/12991977   1.原理         通过调用update来更新位置达到 ...

  8. Flash和滚动字幕

    flash 1.插入flash     1)<object>             <embed src="路径"></embed>      ...

  9. 使用UILabel实现滚动字幕移动效果

    使用UILabel实现滚动字幕移动效果 这个链接中的代码也实现了这种效果 https://github.com/cbpowell/MarqueeLabel 最终效果如下: 原理如下: 1. 获取文本 ...

随机推荐

  1. --- no python application found, check your startup logs for errors

    --- no python application found, check your startup logs for errors 碰到这个问题,请留意下系统执行的python版本和自己的djan ...

  2. [jOOQ中文] 七个步骤快速入门

    https://segmentfault.com/a/1190000010415384 关于jOOQ jOOQ: The easiest way to write SQL in Java jOOQ是一 ...

  3. Tomcat 性能监控工具jvisualvm, JConsole

    配置: 重启Tomcat

  4. tomcat8 安全加固

    本文基于tomcat8.0.24 1.删除文档和示例程序 [操作目的]删除示例文档 [加固方法]删除webapps/docs.examples.manager.ROOT.host-manager [是 ...

  5. (1)activiti认识以及数据库和插件配置

    工作流介绍 工作流(Workflow),就是通过计算机对业务流程自动化执行管理.它主要解决的是“使在多个参与者之间按照某种预定义的规则自动进行传递文档.信息或任务的过程, 从而实现某个预期的业务目标, ...

  6. 迷你MVVM框架 avalonjs 1.2发布

    avalon1.2 带来了许多新特性,让开发更轻松!详见如下: 升级路由系统与分页组件. 对ms-duplex的绑定值进行增强,以前只能prop或prop.prop2,现在可以prop["x ...

  7. 在CentOS上安装tomcat

    先从tomcat网站上下载最新的gz安装包 文件名:apache-tomcat-8.0.8.tar.gz 将文件上传到/usr/local目录中 执行解压缩 tar zxvf apache-tomca ...

  8. Spring Cloud Eureka高可用落地实战

    一.原理 如图所示,多台Server端之间相互注册(这里以两台Server为例),Client端向所有的Server端注册. 二.Server端配置 1. 添加依赖 <dependency> ...

  9. UNITY 多SCENE加载与编辑

    Unity内部场景的加载分为两步: Loading.是指从文件.内存(主要是Streamed scene AssetBundle)中加载Scene的内容,创建并读取所有相关的Game objects. ...

  10. PHP - MongoDB连接攻略

    http://blog.163.com/lgh_2002/blog/static/44017526201261111044608/ 使用PHP的Mongo扩展连接MongoDB.通过new Mongo ...