WindowsPhon8 ScrollViewer+计时器 实现信息自动滚动播放

WindowsPhon8 ScrollViewer+计时器 实现信息自动滚动播放

  XAML示例代码如下:
 <!--应用程序资源-->
    <Application.Resources>
        <local:LocalizedStrings xmlns:local="clr-namespace:WeatherApp" x:Key="LocalizedStrings"/>
        <!-- 文本样式 -->
        <Style x:Key="spTwoDaysCss_txt" TargetType="TextBlock">
            <Setter Property="FontSize"  Value="25" />
            <Setter Property="Foreground"  Value="White"/>
            <Setter Property="TextWrapping" Value="Wrap" />
        </Style>
    </Application.Resources>
 <ScrollViewer Name="svToDayInfo"  HorizontalScrollBarVisibility="Hidden" 
VerticalScrollBarVisibility="Disabled"><TextBlock Foreground="Orange" Opacity="0.85" 
Name="tbkToDayInfo" ManipulationStarted="tbkToDayInfo_ManipulationStarted" 
Text="" Style="{StaticResource spTwoDaysCss_txt}" />
                    </ScrollViewer>

  CS后台代码如下:
        
        #region 页面级全局变量
        ///         
        /// App _currentApp
        ///         
        App _currentApp = (App)Application.Current;

        ///         
        /// 计时器对象
        ///         
        DispatcherTimer disTimer = new DispatcherTimer();
        #endregion

        ///         
        /// 页面加载
        /// 
        /// 
        /// 
        private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {
             //开始当前天气信息滚动播报
             disTimer.Interval = TimeSpan.FromSeconds(0.01);
             disTimer.Tick += disTimer_Tick;
             disTimer.Start();
        }

     
        /// 
        /// 计时器事件
        /// 
        /// 
        /// 
        void disTimer_Tick(object sender, EventArgs e)
        {
            ScrollViewInfo();
        }         
        

        #region 今日天气滚动显示
        /// <summary>
        /// 今日天气滚动显示
        /// </summary>
        private void ScrollViewInfo()
        {
            ScrollViewer sv = this.svToDayInfo;
            if (sv != null && !String.IsNullOrEmpty(this.tbkToDayInfo.Text.Trim()))
            {
                _currentApp.scrollOffset += 0.65;
                double offset = _currentApp.scrollOffset;

                if (offset > sv.ScrollableWidth)
                    _currentApp.scrollOffset = 0.0;

                sv.ScrollToHorizontalOffset(offset);
            }
        }


        /// <summary>
        /// 停止/继续滚动
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tbkToDayInfo_ManipulationStarted(object sender, System.Windows.Input.ManipulationStartedEventArgs e)
        {
            if (disTimer != null)
            {
                if (disTimer.IsEnabled) disTimer.Stop();
                else disTimer.Start();
            }

            e.Complete();
            e.Handled = true;
        }
        #endregion
  
源码下载地址: http://download.csdn.net/download/yimiyuangguang/6945069

以上案例仅供学习参考,如有不足之处还请提出指正,谢谢!

效果图如下:


   
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

追夢秋陽

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值