当前位置: 首页 > wzjs >正文

青岛百度网站排名中国最好的网络营销公司

青岛百度网站排名,中国最好的网络营销公司,wordpress下拉筛选,房地产新闻动态简单的计数案例,ViewModel开启辅助线程,模拟后端运行,该方式可以扩展为项目中的后端线程数采及运算呈现,便于实时监控数据的场景。 代码如下: MyCommand using System; using System.Collections.Generic; using Sys…

简单的计数案例,ViewModel开启辅助线程,模拟后端运行,该方式可以扩展为项目中的后端线程数采及运算呈现,便于实时监控数据的场景。

代码如下:

MyCommand

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;namespace MVVMCountDemo.ViewModel
{public class MyCommand : ICommand{private readonly Action _execute;private readonly Func<bool> _canExecute;public MyCommand(Action execute, Func<bool> canExecute = null){_execute = execute;}public event EventHandler CanExecuteChanged{add { CommandManager.RequerySuggested += value; }remove { CommandManager.RequerySuggested -= value; }}public bool CanExecute(object parameter){return _canExecute == null || _canExecute();}public void Execute(object parameter){_execute();}}
}

Notify  

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;namespace MVVMCountDemo.ViewModel
{public abstract class Notify : INotifyPropertyChanged{public event PropertyChangedEventHandler PropertyChanged;public void OnPropertyChanged([CallerMemberName] string name = null){PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));}}
}

Window.xaml

<Window x:Class="MVVMCountDemo.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:MVVMCountDemo"mc:Ignorable="d"Title="MainWindow" Height="350" Width="525"><Grid><Label  FontSize="30" Content="{Binding Seconds}"   Foreground="Black" HorizontalAlignment="Left" Margin="141,85,0,0" VerticalAlignment="Top" Height="110" Width="230"/><Button Content="开始/清零" HorizontalAlignment="Left" Margin="203,224,0,0" VerticalAlignment="Top" Width="100" Command="{Binding StartOrResetCommand}"/></Grid>
</Window>

MainWindow.cs

using MVVMCountDemo.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;namespace MVVMCountDemo
{/// <summary>/// MainWindow.xaml 的交互逻辑/// </summary>public partial class MainWindow : Window{public MainWindow(){InitializeComponent();this.DataContext = new CountDemoViewModel();}}
}

CountDemoViewModel 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using System.Windows.Threading;namespace MVVMCountDemo.ViewModel
{public class CountDemoViewModel:Notify{private DispatcherTimer timer;private int seconds = 0;public int Seconds{get { return seconds; }set{if (seconds != value){seconds = value;OnPropertyChanged(nameof(Seconds));}}}public ICommand StartOrResetCommand { get; private set; }public CountDemoViewModel(){timer = new DispatcherTimer();timer.Interval = TimeSpan.FromSeconds(1);timer.Tick += Timer_Tick;StartOrResetCommand = new MyCommand(StartOrReset);}int currentCount = 0;int lastCount = 0;private void Timer_Tick(object sender, EventArgs e){currentCount++;Seconds = currentCount - lastCount;}private void StartOrReset(){if (timer.IsEnabled){timer.Stop();Seconds = 0;lastCount = currentCount;}else{timer.Start();}}}
}

http://www.dtcms.com/wzjs/279136.html

相关文章:

  • 建设网站所采用的技术方案注册网站免费注册
  • 域名建议网站程序员培训班要多少钱
  • 可以自己做直播网站吗seo网站优化快速排名软件
  • 男的做直播哪个网站好江门seo推广公司
  • 时时彩做假网站怎么做快速搭建网站的工具
  • 网盘网站开发云盘搜索
  • 沈阳网站建设公司怎么样百度手机助手下载安卓版
  • 龙华住房和建设局网站获客
  • 长春做网站网站营销咨询师
  • 找个做网站的广州各区最新动态
  • 网站如何制作的厦门seo公司到1火星
  • 网站的根目录百度排名查询
  • 规划院网站建设书长尾词在线挖掘
  • 企业站模板互联网营销案例分析
  • 网站推广软文范例软文营销成功案例
  • 网站开发与设计的实训场地12月10日新闻
  • 如何远程连接 网站 数据库今天中国新闻
  • 潍坊做网站优化广州全网推广
  • flask网站开发源码郴州seo快速排名
  • 百度权重高的网站长沙疫情最新数据消息
  • 怎么做百度提交入口网站什么叫软文推广
  • 网上三维展馆网站是怎么做的销售
  • 设计网站页面注意事项企业宣传片
  • 做网站推广多少钱网络推广平台有哪些渠道
  • 荥阳网站制作搜索引擎营销的英文缩写是
  • 4s店网站建设如何优化关键词搜索排名
  • 腾讯云 网站备案超级seo工具
  • 不用下载能直接进入的正能量网站网域名解析ip查询
  • 数据来源于网站怎么做参考文献平台怎么推广
  • 教育行业网站建设审批阿亮seo技术顾问