WPF scroll subtitles and WPF scroll subtitles

Source: Internet
Author: User

WPF scroll subtitles and WPF scroll subtitles

XAML code:

<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" verticalignment = "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 = "" To = "25" Storyboard. targetName = "stackPanel" Storyboard. targetProperty = "RenderTransform. Y "/> </Storyboard> </local: WorkSpaceContent. resources> <Grid Background = "# 00a6da"> <Grid. columnDefinitions> <ColumnDefinition Width = "60"> </ColumnDefinition> </Grid. columnDefinitions> <TextBlock Margin = "15 0 5 0" Text = "announcement: "FontSize =" 12 "Foreground =" # ffff33 "VerticalAlignment =" Center "> </TextBlock> <ScrollViewer Grid. column = "1" Name = "scrollViewer" comment = "Hidden" comment = "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>View Code

Background code:

Using SunCreate. combatPlatform. domain; 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; usin G System. windows. navigation; using System. windows. shapes; namespace SunCreate. combatPlatform. client {// <summary> // rolling display of announcements /// </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_Loade D (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 <INoticeService> (). getListPage (null, DateTime. minValue, DateTime. now, 1, 3, ref total ). toList (); _ data. reverse (); _ index = _ data. count-1; Dispatcher. beginInvoke (new Action () => {st AckPanel. 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 () ;})); _ ind Ex --; 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 ();}}}View Code

:

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.