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. MySQL转Oracle,MyBatis Mapper XML 文件修改项总结

    1.对于批量插入 需要更改成 <insert id="saveAll"> insert into(a,b,c) <foreach collection=" ...

  2. 263. Ugly Number + 264. Ugly Number II + 313. Super Ugly Number

    ▶ 三个与丑数相关的问题 ▶ 第 263题,判定一个数字是否是丑数,即其素因子是否仅由 2,3,5 构成. ● 常规消除判别,4 ms class Solution { public: bool is ...

  3. Mysql 索引优化 - 1

    单表  范围查询 后面的索引会失效 双表  左右连接建立索引互相使用 三表   用小结果集驱动大表结果, 先优化括号里面的SQL, 保证JOIN被驱动的表上ON字段有索引 索引失效(常见原因) 全职匹 ...

  4. MVC-READ3(视图引擎主要类关系图)

  5. 迷你MVVM框架 avalonjs 学习教程2、模块化、ViewModel、作用域

    一个项目是由许多人分工写的,因此必须要合理地拆散,于是有了模块化.体现在工作上,PM通常它这为某某版块,某某频道,某某页面.某一个模块,必须是包含其固有的数据,样式,HTML与处理逻辑.在jQuery ...

  6. MyBatis 注解式开发

  7. 带入gRPC:gRPC Streaming, Client and Server

    带入gRPC:gRPC Streaming, Client and Server 原文地址:带入gRPC:gRPC Streaming, Client and Server 前言 本章节将介绍 gRP ...

  8. gRPC初探——概念介绍以及如何构建一个简单的gRPC服务

    目录 引言 1. gRPC简介 2. 使用Protocol Buffers进行服务定义 2.1 定义消息 2.2 定义服务接口 3.构建简单的gRPC服务 3.1 编写proto文件,定义消息和接口 ...

  9. linux sudo 系统环境变量 用户环境变量

    1. sudo就是普通用户临时拥有root的权限.好处在于,大多数时候使用用户自定义的配置,少数情况可以通过sudo实现root权限做事. 故而,需要注意的一点是,在你使用了sudo后,你临时不再是原 ...

  10. params must be [a-zA-Z0-9] for verification sms

    阿里短信发送短信时返回这个信息,之前是可以发送的,现在阿里应该是做了限制的.如果你的短信模板类型为“验证码”,发送的短信内容只能是包含字母和数字 所以当你的短信内容包含特殊符号和中文时,请把短信模板类 ...