mounika madhavaram

mounika madhavaram

  • NA
  • 42
  • 10.7k

In wpf mvvm how to get button enabled when checkbox is check

Apr 3 2018 7:27 AM
this is my xaml code
  1. <controls:ProCheckBox Grid.Row="0" Grid.Column="1" Content="{Binding CheckBoxContent, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"  
  2. Margin="0,5,0,5" IsChecked="{Binding IsChecked,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" />  
  3. <controls:ProButton Content="REQUEST" HorizontalAlignment="Right" Margin="0,0,2,0" VerticalAlignment="Center"  
  4. Command="{Binding ApproveCommand,UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}" BackgroundColor="MaterialBlue"  
  5. ToolTipService.ToolTip="{x:Static displayText:CommonStrings.ButtonSave}"  
  6. IsEnabled="{Binding IsChecked,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged,Converter={StaticResource BooleanToVisibilityConverter} }"  
  7. Visibility="{Binding IsRequest,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged,Converter={StaticResource BooleanToVisibilityConverter} }" >  
  8. </controls:ProButton>  
this is my viewmodel
  1. private bool _isApproval;  
  2. public bool IsApproval  
  3. {  
  4. get { return _isApproval; }  
  5. set  
  6. {  
  7. this.SetProperty(ref this._isApproval, value, "IsApproval");  
  8. }  
  9. }  
  10. private bool _isrequest;  
  11. public bool IsRequest  
  12. {  
  13. get { return _isrequest; }  
  14. set  
  15. {  
  16. this.SetProperty(ref this._isrequest, value, "IsRequest");  
  17. }  
  18. }  
  19. private bool _isChecked;  
  20. public bool IsChecked  
  21. {  
  22. get { return _isChecked; }  
  23. set { _isChecked = value; OnPropertyChanged("IsChecked"); }  
  24. }  
  25. private string _checkBoxContent;  
  26. public string CheckBoxContent  
  27. {  
  28. get { return _checkBoxContent; }  
  29. set  
  30. {  
  31. this.SetProperty(ref this._checkBoxContent, value, "CheckBoxContent");  
  32. }  
  33. }  
  34. public ICommand ApproveCommand { getset; }  
  35. public ICommand RejectCommand { getset; }  
  36. // public object SelectedItem { get; private set; }  
  37. private Action<bool> _dialogClosedCallback;  
  38. public async override void OnNavigatedTo(NavigationContext navigationContext)  
  39. {  
  40. _reportWrapperService = ServiceLocator.Current.GetInstance<IReportWrapperService>(typeof(IReportWrapperService).Name);  
  41. base.OnNavigatedTo(navigationContext);  
  42. var parameters = navigationContext.Parameters;  
  43. ContainersDO = parameters[AppConstants.NavigationParameterNames.Container] as ContainersDO;  
  44. ContainerAct = parameters[AppConstants.NavigationParameterNames.ContainerActivity] as ContainerActivitiesDO;  
  45. _dialogClosedCallback = navigationContext.Parameters[AppConstants.NavigationParameterNames.CallBack] as Action<bool>;  
  46. CheckBoxContent = "Draft Approved";  
  47. IsApproval = false;  
  48. if (ContainerAct.Code == "3")  
  49. {  
  50. IsApproval = true;  
  51. // IsRequest = false;  
  52. CheckBoxContent = "Request for draft approval";  
  53. }  
  54. ContainerInformationModel = new ContainerInformationViewModel();  
  55. if (ContainersDO != null)  
  56. {  
  57. }  
  58. }  
  59. public DraftCostingViewModel()  
  60. {  
  61. ContainersDO = new ContainersDO();  
  62. _jobWrapperService = ServiceLocator.Current.GetInstance<IJobWrapperService>(typeof(IJobWrapperService).Name);  
  63. ApproveCommand = new DelegateCommand(ExecuteApproveCommand);  
  64. RejectCommand = new DelegateCommand(ExecuteRejectCommand);  
  65. ContainerActivities = new ContainerActivityDetailsDO();  
  66. }

Answers (2)