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. Windows下cpu使用的监控

    这里有一篇来自微软的文章,主要讲WPA如何使用,但是前面关于进程调度的介绍很给力,非常好的学习操作系统的材料: https://msdn.microsoft.com/en-us/library/jj6 ...

  2. vue轮播(完整详细版)

    轮播组件vue <swiper :options="swiperOption" class='swiper-box'>     <swiper-slide v-f ...

  3. .NET 同步 异步 委托

    1.定义委托: using System; using System.Collections.Generic; using System.IO; using System.Linq; using Sy ...

  4. CImage 往Picture Control贴图 图像显示不正常

    在使用CImage 往vc控件 picture Control 上贴图的时候图像显示不太正常如图: 已知原始图片的宽高为640*640  而我上面picture Control  控件宽高小于原始图像 ...

  5. aria2自动更新BT Tracker服务器列表脚本

    vi /root/trackers-list-aria2.sh 内容如下: #!/bin/bash #/usr/sbin/service aria2 stop list=`wget -qO- http ...

  6. Canvas.Pixels 实例:判断一点是否在区域中

    The Windows 3.1 and Windows 95 GDI heap is limited in regards to scan converting large and complex r ...

  7. 在spring中使用quartz配置作业的二种方式

  8. python实例、类方法、静态方法

    [python实例.类方法.静态方法] 参考:http://blog.163.com/yang_jianli/blog/static/161990006201122411586729/

  9. FP扣损耗逻辑代码

    芯片172没有扣减损耗, 取数:SAP_STPO的AUSCH   IN_BOM_DETAILS:耗损比例COMPONENT_YIELD_UOM   存储过程FP_MO2SAP:supplydmdpeg ...

  10. Bean标签的常用属性

    -----------------siwuxie095 Bean 标签的常用属性 1.id 属性:Bean 的唯一标识名,必须以字母开头,且不能 包含特殊字符 2.class 属性:用来定义类的全限定 ...