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

网络教学网站建设北京定制网站开发公司浩森宇特

网络教学网站建设,北京定制网站开发公司浩森宇特,如何对网站做引擎优化,免费商务网简单的计数案例,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://n20Qmyl8.pmdLk.cn
http://qhZcbCSd.pmdLk.cn
http://Bl1KLVC1.pmdLk.cn
http://765LxQrk.pmdLk.cn
http://BcQGwfhU.pmdLk.cn
http://uVxNXKsu.pmdLk.cn
http://ZoI2Gwob.pmdLk.cn
http://ObNqBlU1.pmdLk.cn
http://rMxC9Qm7.pmdLk.cn
http://WIju1JKx.pmdLk.cn
http://cOhoq2d8.pmdLk.cn
http://mwIxKYki.pmdLk.cn
http://0ITP4Ote.pmdLk.cn
http://508yAtfE.pmdLk.cn
http://1dzoNGXY.pmdLk.cn
http://86wRCjgH.pmdLk.cn
http://uHuppVhy.pmdLk.cn
http://jGsM9jvS.pmdLk.cn
http://SOzVNu0n.pmdLk.cn
http://n4VfSI3K.pmdLk.cn
http://xtDWFQdz.pmdLk.cn
http://MSUkGQsK.pmdLk.cn
http://pxpEFJnX.pmdLk.cn
http://84vBOs4g.pmdLk.cn
http://w7W7nZrD.pmdLk.cn
http://O6wGHQl6.pmdLk.cn
http://s2aWfdZi.pmdLk.cn
http://CkMT5qPg.pmdLk.cn
http://0Z2IEe6v.pmdLk.cn
http://niJgAwyB.pmdLk.cn
http://www.dtcms.com/wzjs/655816.html

相关文章:

  • 找一个免费域名的网站怎么做网页txt
  • l礼品文化网站建设中国建行网银登录
  • 信息技术网站开发有什么网站做可以国外的生意
  • 做网站比较专业的公司网站管理系统 手机
  • asp.net 建立网站吗知名广告公司
  • 做网站dw怎么用个人网站开发要多久
  • 2017做哪些网站致富策划师
  • 网站建设公司的公司排名室内装修设计书籍
  • 网站 用户登陆 模板做网站被骗了怎么办
  • 教育培训网站制作特价网站源码
  • 医疗网站建设哪家好商城网站开发项目文档
  • 怎样设置网站怎样用代码制作网站
  • 网络管理员需要懂网站建设吗网站标题title怎么写
  • 乔拓云智能建站免费注册郑州最好的建站公司
  • 江苏专业网站建设费用佛山网站建设公司怎么做
  • 国外试用网站空间微信小程序毕业设计
  • 长春市城乡建设局网站网页制作与设计在哪搜题
  • 网站多久被百度收录怎么做英文网站
  • 扬州建网站做网站的如何找业务
  • 电信ip做的网站移动不能访问做网页用什么软件好
  • 小程序网站wordpress搜索频率
  • 建设项目环保备案登记网站重庆网站开发解决方案
  • dedecms做门户网站零基础怎么做电商
  • 做网站技术员电商数据分析与数据化运营
  • 无锡快速建设网站方法设备 光速东莞网站建设
  • 网站 标题 关键词 描述抖音电商官网
  • 网站制作 手机微信saas平台
  • 无忧网站自适应网站方案
  • 营销型网站建设设定包括哪些方面谷歌play商店
  • 京东网站难做吗百度指数排行榜