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

昆明市网站建设_网站建设公司_Bootstrap_seo优化

南昌专业做网站公司有哪些,代刷网站是怎么做的,php手机网站怎么做,江苏宿迁房产网这节我们介绍一下WPF中比较重要的接口ICommand#xff0c;也是WPF中一个新的特性#xff0c;做过WinForm朋友都知道#xff0c;WinForm开发是基于事件驱动开发模式#xff0c;比如一个Button有Click事件#xff0c;当我点击该按钮时#xff0c;在当前页面会执行具体的业务…这节我们介绍一下WPF中比较重要的接口ICommand也是WPF中一个新的特性做过WinForm朋友都知道WinForm开发是基于事件驱动开发模式比如一个Button有Click事件当我点击该按钮时在当前页面会执行具体的业务这样带来的UI和业务层产生紧密的耦合WPF也继承了WinForm这一旧的开发模式同时给我们添加了新的方法使得UI和后端业务完全隔离从而UI和业务逻辑解耦我们来看一下该接口的定义public interface ICommand{event EventHandler CanExecuteChanged;bool CanExecute(object parameter);void Execute(object parameter);}在整个MVVM架构中该接口起着非常重要的作用我们来看一下该接口成员CanExecuteChanged事件触发通知UI界面做出响应比如按钮禁用或启用表示CanExecute该接口返回一个bool值表示是否执行命令返回true命令执行false命令不执行。我们通过一个简单的例子实现命令绑定需求比较简单我们定义一个输入框如果为空状态提交按钮禁用如果有值按钮启用点击提交并将值显示到页面。我们定义一个DelegateCommand 实现ICommand接口public class DelegateCommand : ICommand{private Action _execute;private Funcbool _canExecute;public DelegateCommand(Action executeMethod){_execute executeMethod;}public DelegateCommand(Action executeMethod, Funcbool canExecute): this(executeMethod){this._canExecute canExecute;}public bool CanExecute(object parameter){return _canExecute();}public event EventHandler CanExecuteChanged {add{CommandManager.RequerySuggested value;}remove{CommandManager.RequerySuggested - value;}}public void Execute(object parameter){_execute();}}接下来我们定义一个ViewMode类命名为SampleViewModel实现INotifyPropertyChanged接口public class SampleViewModel : INotifyPropertyChanged{public event PropertyChangedEventHandler PropertyChanged;private void NotifyPropertyChanged([CallerMemberName] String propertyName ){PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));}private string name String.Empty;public string Name{get{return name;}set{if (value ! this.name){this.name value;NotifyPropertyChanged();}}}private string displayName string.Empty;public string DisplayName{get { return displayName; }set{if (value ! this.displayName){displayName value;NotifyPropertyChanged();}}}ICommand delegateCommand;public ICommand DelegateCommand{get{if (delegateCommand null){delegateCommand new DelegateCommand(Execute, CanExecute);}return delegateCommand;}}public void Execute(){DisplayName Name;}public bool CanExecute(){return !string.IsNullOrEmpty(Name);}}  XMLA页面定义Window x:ClassExample_21.MainWindowxmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentationxmlns:xhttp://schemas.microsoft.com/winfx/2006/xamlxmlns:dhttp://schemas.microsoft.com/expression/blend/2008xmlns:mchttp://schemas.openxmlformats.org/markup-compatibility/2006xmlns:localclr-namespace:Example_21mc:IgnorabledTitleMainWindow Height450 Width800GridGrid.RowDefinitionsRowDefinition/RowDefinitionRowDefinition/RowDefinitionRowDefinition/RowDefinition/Grid.RowDefinitionsTextBox Grid.Row0 NametxtBox Width200 Text{Binding PathName,UpdateSourceTriggerPropertyChanged} VerticalAlignmentCenter HorizontalAlignmentCenter/TextBlock Grid.Row1 Width200 Text{Binding PathDisplayName}/TextBlockButton Grid.Row2 x:UidbtnSend x:NamebtnSend FontSize16 Content提交 Width100 Height50 Margin0,0,0,5 Command{Binding DelegateCommand} /Button/Grid /WindowMainWindow.xaml.cs 文件public partial class MainWindow : Window{public MainWindow(){InitializeComponent();this.DataContext new SampleViewModel();}}从上面的例子可以看出我们可以使用控件的Command属性来绑定要执行的命令我们还可以设置CommandParameter来传递参数可以把UI上数据传递到后台WPF整个框架是基于数据驱动我们可以做到把UI层完全剥离出来所以说WPF是一个前端和后台可以完全分离的框架。其实走到这里结合我们WPF-18 INotifyPropertyChanged 接口我们有点看到了MVVM开发模式的影子。接下来我们使用MVVM模式做一个简单的Demo
http://www.lebaoying.cn/news/83181.html

相关文章:

  • 做美食分享网站源码六安同城网
  • 目前比较流行的公司网站建站技术深圳注册公司地址新规定
  • 推广网站怎样做做网站必备语言
  • 福建省建设职业管理中心网站茶叶网站模板下载
  • 国外设计文章的网站中山网站建设文化机构
  • 邢台建设厅网站wordpress注册弹窗代码
  • 利用微博做网站推广网站需要具备条件
  • 网站建设 移动端界面设计师培训
  • 做汽配的都上什么网站湖北省住房和建设厅官方网站
  • php做的大型网站有哪些专业网站建设行业现状
  • 对网站主要功能界面进行赏析重庆五号线金建站
  • 原墨网站建设北京培训学校
  • 天津网站优化排名推广免费凡客建站官网
  • 菏泽网站建设效果宝安网站设计哪家好
  • 网站快速收录技术河南百度推广代理商
  • 在线做logo印章网站池州哪家做网站
  • 许昌网站建设公司排行榜网建平台
  • 做招商加盟网站网站推广方式介绍
  • 深圳网站建设公司为什wordpress 同步微信
  • 做网站拉广告建站制作企业
  • 做设计找素材那个网站最好用西宁网站建设学校
  • 高端大气的网站制作菠菜网站建设条件
  • 支付网站开发建设费用怎么入账wordpress 动态菜单
  • 人才网网站方案网络科技网站
  • 中小学网站建设建议dw网页制作在线编辑
  • 南宁做网站设计方案永久免费手机网站自助建站
  • 网站开发和程序开发的却别精仿虎嗅网wordpress
  • 做的好的网站着陆页html网页设计大作业
  • 下载图片的网站建设网站5g空间
  • 开通qq空间申请网址网站建设seo 视频教程