最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

WPF實現(xiàn)上下滾動字幕效果

 更新時間:2017年10月10日 14:10:37   作者:秋荷雨翔  
這篇文章主要為大家詳細介紹了WPF實現(xiàn)上下滾動字幕效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了WPF上下滾動字幕的具體代碼,供大家參考,具體內(nèi)容如下

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 = 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(() =>
   {
    stackPanel.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();
  }));

  _index--;
  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();
 }
 }
}

效果圖:

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

  • 配置C#的系統(tǒng)環(huán)境變量的方法

    配置C#的系統(tǒng)環(huán)境變量的方法

    配置C#的系統(tǒng)環(huán)境變量的方法...
    2007-03-03
  • 利用C#守護Python進程的方法

    利用C#守護Python進程的方法

    這篇文章主要給大家介紹了關于如何利用C#守護Python進程的相關資料,文中通過示例代碼介紹的非常詳細,對大家學習或者使用C#具有一定的參考學習價值,需要的朋友們下面來一起學習學習吧
    2019-10-10
  • c#得到本月有幾周和這幾周的起止時間示例代碼

    c#得到本月有幾周和這幾周的起止時間示例代碼

    本篇文章主要是對c#得到本月有幾周和這幾周的起止時間的示例代碼進行了介紹,需要的朋友可以過來參考下,希望對大家有所幫助
    2014-01-01
  • 詳解c# 類型轉(zhuǎn)換

    詳解c# 類型轉(zhuǎn)換

    這篇文章主要介紹了c# 類型轉(zhuǎn)換的相關資料,文中講解非常細致,代碼幫助大家更好的理解和學習,感興趣的朋友可以學習
    2020-07-07
  • C#獲取文件MD5值的實現(xiàn)示例

    C#獲取文件MD5值的實現(xiàn)示例

    文件的md5值,即文件簽名,為了驗證文件的正確性,是否被惡意篡改等。每個文件有一個唯一的md5。下面這篇文中就給大家介紹了如何利用C#獲取文件MD5值,有需要的朋友們可以參考借鑒,下面來一起看看吧。
    2016-12-12
  • 通過C#編寫一個簡易的Windows截屏增強工具

    通過C#編寫一個簡易的Windows截屏增強工具

    在使用?Windows?系統(tǒng)的截屏快捷鍵?PrintScreen?截屏時,如果需要把截屏保存到文件,需要先粘貼到畫圖工具然后另存為文件。所以本文用C#編寫了一個簡易的Windows截屏增強工具,需要的可以參考一下
    2022-05-05
  • C# 打開電子郵件軟件的具體方法

    C# 打開電子郵件軟件的具體方法

    這篇文章介紹了C# 打開電子郵件軟件的具體方法,有需要的朋友可以參考一下
    2013-11-11
  • WPF利用RichTextBox實現(xiàn)富文本編輯器

    WPF利用RichTextBox實現(xiàn)富文本編輯器

    在實際應用中,富文本隨處可見,那么在WPF開發(fā)中,如何實現(xiàn)富文本編輯呢?本文以一個簡單的小例子,簡述如何通過RichTextBox實現(xiàn)富文本編輯功能,需要的可以參考下
    2024-02-02
  • c# datetime方法應用介紹

    c# datetime方法應用介紹

    本文將詳細介紹c# datetime方法應用,需要了解更多的朋友可以參考下
    2012-11-11
  • C#獲取字符串后幾位數(shù)的方法

    C#獲取字符串后幾位數(shù)的方法

    這篇文章主要介紹了C#獲取字符串后幾位數(shù)的方法,實例分析了C#操作字符串的技巧,具有一定參考借鑒價值,需要的朋友可以參考下
    2015-03-03

最新評論

霍山县| 奈曼旗| 博兴县| 东海县| 奉新县| 犍为县| 汉沽区| 涿州市| 小金县| 万盛区| 沅江市| 海林市| 姜堰市| 广灵县| 同德县| 绥宁县| 肥城市| 临沂市| 闸北区| 黑山县| 乌兰浩特市| 大丰市| 和平区| 怀化市| 昌乐县| 福建省| 新竹县| 博白县| 凤山市| 于都县| 高唐县| 合肥市| 平遥县| 望谟县| 平顶山市| 新营市| 通化市| 东辽县| 宜城市| 满洲里市| 巴里|