System.Windows.Threading.DispatcherTimer小例子

本文介绍了一个使用 Silverlight 实现的简单动画效果案例。通过 DispatcherTimer 控件定时更新 Canvas 的宽度和高度来实现动画效果。该案例展示了如何在 Silverlight 中创建计时器并利用该计时器改变 UI 元素的属性。
 
<Canvas x:Name="can" Loaded="StartTimer" Background="Blue"/>

 

 

namespace SilverlightApplication1
{
    
public partial class Page : UserControl
    
{
       
        
int i = 0;
        
public Page()
        
{
            InitializeComponent();
        }

        
public void StartTimer(object o, RoutedEventArgs sender)
        
{
            System.Windows.Threading.DispatcherTimer t 
= new System.Windows.Threading.DispatcherTimer();
            t.Interval 
= new TimeSpan(0000100);
            t.Tick 
+= new EventHandler(t_Tick);
            t.Start();
        }

        
void t_Tick(object sender, EventArgs e)
        
{
            can.Width 
= i++;
            can.Height 
= i++;
        }

    }

}
<Window x:Class="_232323.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:_232323" mc:Ignorable="d" Title="MainWindow" Height="650" Width="1200" Closed="Window_Closed"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="Auto" /> <RowDefinition Height="*" /> </Grid.RowDefinitions> </Window> using System.Collections.ObjectModel; using System.IO; using System.Text.Json; using System.Windows; using System.Windows.Controls; using System.Windows.Media; using System.Windows.Shapes; using System.Windows.Threading; using System.Text.RegularExpressions; using Path = System.IO.Path; namespace _232323 { /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window { private PlcMonitorViewModel _viewModel; private AppConfig _appConfig = new AppConfig(); private PlcService? _plcService; private DispatcherTimer? _readTimer; private DispatcherTimer? _heartbeatTimer; private bool _isConnected = false; private int _stationNumber = 1; private int _connectionRetryCount = 0; private CancellationTokenSource? _readCancellationTokenSource; }using ActUtlType64Lib; namespace _232323 { } using System.Collections.ObjectModel; using System.ComponentModel; using System.Text.Json.Serialization; using System.Runtime.CompilerServices; namespace _232323 { public class MotorPointData : INotifyPropertyChanged { }帮我分析一下上面代码逻辑结构有没有问题,是否符合工业化的标准,读取方式还有长时间运行时会不会发生卡顿,详细分析给出建议
最新发布
09-14
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值