WPF MVVM示例讲解

2019-12-26 13:10:24刘景俊
  • public void Execute(object parameter)  { 
  • ZoomType type = (ZoomType)Enum.Parse(typeof(ZoomType), (string)parameter, true);  switch(type) 
  • {  case ZoomType.Normal: 
  • _data.Zoom = 1;  break; 
  • case ZoomType.ZoomIn:  _data.Zoom *= 1.2; 
  • break;  case ZoomType.ZoomOut: 
  • _data.Zoom /= 1.2;  break; 
  • }  } 
  • MainViewModel:

     

     
    1. public class MainViewModel : ViewModelBase  { 
    2. private string _imagePath;  public string ImagePath 
    3. {  get 
    4. {  return _imagePath; 
    5. }  set 
    6. {  if (_imagePath != value) 
    7. {  _imagePath = value; 
    8. OnPropertyChanged("ImagePath");  } 
    9. }  } 
    10. private double _zoom = 1.0;  public double Zoom 
    11. {  get 
    12. {  return _zoom; 
    13. }  set 
    14. {  if(_zoom != value) 
    15. {  _zoom = value; 
    16. OnPropertyChanged("Zoom");  } 
    17. }  } 
    18. private ICommand _openFileCommand;  public ICommand OpenFileCommand 
    19. {  get { return _openFileCommand; }