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

网站流量统计表格/搜索引擎技术优化

网站流量统计表格,搜索引擎技术优化,济南哪家网站技术比较高,北京通州网站设计公司如下图是系统的结构图:这个示例是模仿计算器的MVVM模式的精简版,非常简单。 这篇文章就开门见山了,有关MVVM的理论部分,请参考MVVM设计模式 1、App中的代码: public App() {CalculatorView view new CalculatorView()…

如下图是系统的结构图:这个示例是模仿计算器的MVVM模式的精简版,非常简单。

这篇文章就开门见山了,有关MVVM的理论部分,请参考MVVM设计模式

1、App中的代码:

public App()
{
    CalculatorView view = new CalculatorView();
    view.DataContext = new CalculatorViewModel();
    view.Show();
}

2、Model层中CauculatorModel的代码

class CauculatorModel
{
     public string FirstOperand { get; set; }
     public string SecondOperand { get; set; }
     public string Operation { get; set; }
     public string Result { get; set; }
}

3、Command

public class DeletgateCommand<T>:ICommand
 {
     private readonly Action<T> _executeMethod = null;
     private readonly Func<T,bool> _canExecuteMethod = null;
     public DeletgateCommand(Action<T> executeMethod)
         : this(executeMethod, null)
     { }
     public DeletgateCommand(Action<T> executeMethod, Func<T,bool> canExecuteMethod) 
     {
         if (executeMethod == null)
             throw new ArgumentNullException("executeMetnod");
         _executeMethod = executeMethod;
         _canExecuteMethod = canExecuteMethod;
     }
     #region ICommand 成员
     /// <summary>
     ///  Method to determine if the command can be executed
     /// </summary>
     public bool CanExecute(T parameter)
     {
         if (_canExecuteMethod != null)
         {
             return _canExecuteMethod(parameter);
         }
         return true;
     }
     /// <summary>
     ///  Execution of the command
     /// </summary>
     public void Execute(T parameter)
     {
         if (_executeMethod != null)
         {
             _executeMethod(parameter);
         }
     }
     #endregion
     event EventHandler ICommand.CanExecuteChanged
     {
         add { CommandManager.RequerySuggested += value; }
         remove { CommandManager.RequerySuggested -= value; }
     }
     #region ICommand 成员
     public bool CanExecute(object parameter)
     {
         if (parameter == null && typeof(T).IsValueType)
         {
             return (_canExecuteMethod == null);
         }
          
         return CanExecute((T)parameter);
     }
     public void Execute(object parameter)
     {
         Execute((T)parameter);
     }
     #endregion
 }

 

4、ViewModwl层,为了简化,此处Add方法采用硬编码的形式

public class CalculatorViewModel
 {
     CauculatorModel calculatorModel;
     private DeletgateCommand<string> addCommand;
      
     public CalculatorViewModel()
     {
         calculatorModel = new CauculatorModel();
     }
     #region Public Properties
     public string FirstOperand
     {
         get return calculatorModel.FirstOperand;  }
         set { calculatorModel.FirstOperand = value;  }
     }
     public string SecondOperand
     {
         get { return calculatorModel.SecondOperand; }
         set { calculatorModel.SecondOperand = value; }
     }
     public string Operation
     {
         get { return calculatorModel.Operation; }
         set { calculatorModel.Operation = value; }
     }
     public string Result
     {
         get { return calculatorModel.Result; }
         set { calculatorModel.Result = value; }
     }
     #endregion
     public ICommand AddCommand
     {
         get
         {
             if (addCommand == null)
             {
                 addCommand = new DeletgateCommand<string>(Add, CanAdd);
             }
             return addCommand;
         }
     }
         
     public  void Add(string x)
     {
         FirstOperand = x;
         SecondOperand = x;
         Result = (double.Parse(FirstOperand) + double.Parse(SecondOperand)).ToString();
         Operation = "+";
         MessageBox.Show( FirstOperand+ Operation +SecondOperand +"=" + Result);
     }
     private static bool CanAdd(string num)
     {
         return true;
     }
 }

 

ViewModelBase中的代码:

public abstract class ViewModelBase : INotifyPropertyChanged
 {
     public event PropertyChangedEventHandler PropertyChanged;
     protected void OnPropertyChanged(string propertyName)
     {
         PropertyChangedEventHandler handler = PropertyChanged;
         if (handler != null)
         {
             handler(this, new PropertyChangedEventArgs(propertyName));
         }
     }
 }

 5、View层

<Grid>   
       <TextBox  Height="23" Margin="12,63,0,0" Name="textBox1" VerticalAlignment="Top" HorizontalAlignment="Left"  Width="120" />
       <Label Margin="12,25,95,0" Name="label2" Height="32" VerticalAlignment="Top">请输入x的值! x+x=? </Label>
       <Button Height="23" Command="{Binding AddCommand}"  
               CommandParameter="{Binding ElementName=textBox1,Path=Text}"   HorizontalAlignment="Left" Margin="12,102,0,0" Name="button1" VerticalAlignment="Top" Width="75">
           确定</Button>
   </Grid>

 CommandParameter里传递的是一个参数,当然可以传递多个参数。

6、效果图:

参考资料:MVVM的一个Example

 


本文转自Work Hard Work Smart博客园博客,原文链接:http://www.cnblogs.com/linlf03/archive/2011/09/11/2173833.html,如需转载请自行联系原作者

http://www.lbrq.cn/news/1534339.html

相关文章:

  • html5 微信网站 源码/阿里云域名注册官网网址
  • 在招聘网站做销售/百度游戏
  • 网页设计师职位要求/seo教程seo官网优化详细方法
  • axure做高保真网站效果图/网站设计公司苏州
  • 网站用oracle做数据库/哪家公司建设网站好
  • 南京华璋建设网站/提高关键词排名的软文案例
  • 兰州企业 网站建设/软文营销成功案例
  • wordpress插件汉化/网页优化
  • 企业服务代理公司/百度seo优化分析
  • wordpress公式编辑器/佛山市seo推广联系方式
  • 建设行政管理部门网站/爱战网关键词工具
  • 太原营销型网站建设/洛阳网站seo
  • 中小网站建设都有哪些/百度注册新账号
  • 苏州工业园区图片/seo实战培训班
  • 做网站需要会什么条件/百度竞价推广
  • 网站聊天工具代码/清理大师
  • 微网站开发/网站做优化一开始怎么做
  • 企业备案网站内容/网络推广外包一年多少钱
  • 做教育类的网站名/怎么做推广网络
  • 网站建设与管理是干嘛的/网络推广企划
  • 2008建立的php网站慢/谷歌seo推广公司
  • 光电网站设计/武汉网络广告推广服务
  • 做海报有哪些网站/新闻小学生摘抄
  • 网站用开源cms/今日刚刚发生的新闻
  • 先做网站再付款/代写
  • 重庆企业网站建设官网/学校网站建设哪家好
  • 北京网站设计培训班/2023年免费进入b站
  • 网站设计 广州/新东方在线koolearn
  • wordpress直播/seo综合查询网站
  • html动态网站开发前景/广东网络优化推广
  • 虚拟机部署HDFS集群
  • Altium Designer 22使用笔记(8)---PCB电气约束设置
  • ​​pytest+yaml+allure接口自动化测试框架
  • InfoNES模拟器HarmonyOS移植指南
  • Arthas 全面使用指南:离线安装 + Docker/K8s 集成 + 集中管理
  • 数据泵实施VPS海外:跨国数据同步的完整解决方案