Textboxes are empty no need to enable a button....

Apr 19 2018 12:28 AM
HI Am using wpf xaml...i have 3 textboxex and one button that button has isenabled property that is binded to other property Isfinalised....if the textbox values are empty i need to get the button disabled(isenabled false) other wise it should be in enable true mode
 
see the xaml code
  1. <controls:ProTextBlock Text="{x:Static displayText:CommonStrings.Party_}" Grid.Row="0" Grid.Column="2" Margin="5,0,0,0" HorizontalAlignment="Left" Width="92"></controls:ProTextBlock>  
  2. <controls:ProTextBox Grid.Row="0" Grid.Column="3" HorizontalAlignment="Stretch" TabIndex="3" Margin="5,0,0,0" Height="25"  
  3. IsEnabled="{Binding InvoiceHeader.IsEnabled,UpdateSourceTrigger=PropertyChanged}"  
  4. Text="{Binding InvoiceHeader.CustomerName,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}">  
  5. </controls:ProTextBox>  
  6. <controls:ProTextBlock Text="Address : " Grid.Row="1" Grid.Column="2" Margin="5,0,0,0" HorizontalAlignment="Left" VerticalAlignment="Center" ></controls:ProTextBlock>  
  7. <controls:ProTextBox Grid.Row="1" Grid.Column="3" Margin="5,0,0,0" TabIndex="4"  
  8. IsEnabled="{Binding InvoiceHeader.IsEnabled,UpdateSourceTrigger=PropertyChanged}"  
  9. VerticalAlignment="Center" VerticalContentAlignment="Center"  
  10. HorizontalAlignment="Stretch" Height="25"  
  11. Text="{Binding InvoiceHeader.CustomerAddress,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}">  
  12. </controls:ProTextBox>  
  13. <controls:ProTextBlock Text="Phone :" Grid.Row="2" Grid.Column="2" Margin="5,0,0,0" HorizontalAlignment="Left" ></controls:ProTextBlock>  
  14. <controls:ProTextBox Grid.Row="2" Grid.Column="3" TabIndex="5" Margin="5,0,0,0"  
  15. IsEnabled="{Binding InvoiceHeader.IsEnabled,UpdateSourceTrigger=PropertyChanged}"  
  16. HorizontalAlignment="Stretch" Height="25" Text="{Binding InvoiceHeader.CustomerPhone,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}">  
  17. </controls:ProTextBox>  
  18. <controls:ProImageButton ImageType="Add"  
  19. Command="{Binding AddInvoiceDetailsCommand}" Style="{DynamicResource ImageButton}"  
  20. Background="{x:Null}"  
  21. IsEnabled="{Binding InvoiceHeader.IsEnabled,UpdateSourceTrigger=PropertyChanged}"  
  22. BorderThickness="0" />  
And properties of buttons are
  1. private bool? _isFinalized;  
  2. public bool? IsFinalized  
  3. {  
  4. get { return this._isFinalized; }  
  5. set { this.SetProperty(ref this._isFinalized, value, () => this.IsFinalized); }  
  6. }  
  7. public bool IsEnabled { get { return !Convert.ToBoolean(IsFinalized); } }  
  8. private string _customerName;  
  9. [Required]  
  10. public string CustomerName  
  11. {  
  12. get { return this._customerName; }  
  13. set { this.SetProperty(ref this._customerName, value, () => this.CustomerName); }  
  14. }  
  15. private string _customerAddress;  
  16. [Required]  
  17. public string CustomerAddress  
  18. {  
  19. get { return this._customerAddress; }  
  20. set { this.SetProperty(ref this._customerAddress, value, () => this.CustomerAddress); }  
  21. }  
  22. private string _customerPhone;  
  23. [Required]  
  24. public string CustomerPhone  
  25. {  
  26. get { return this._customerPhone; }  
  27. set { this.SetProperty(ref this._customerPhone, value, () => this.CustomerPhone); }  
  28. }  
In view model i have a constructor
  1. private InvoiceHeaderDO _invoiceHeader;  
  2. public InvoiceHeaderDO InvoiceHeader  
  3. {  
  4. get  
  5. {  
  6. return _invoiceHeader;  
  7. }  
  8. set  
  9. {  
  10. _invoiceHeader = value;  
  11. OnPropertyChanged("InvoiceHeader");  
  12. }  
  13. }  
  14. private ILookupWrapperService _lookupWrapperService;  
  15. private IFinanceWrapperService _financeWrapperService;  
  16. public ICommand SaveInvoicesCommand { getset; }  
  17. public InvoiceDetailsViewModel()  
  18. {  
  19. _lookupWrapperService = ServiceLocator.Current.GetInstance<ILookupWrapperService>(typeof(ILookupWrapperService).Name);  
  20. _financeWrapperService = ServiceLocator.Current.GetInstance<IFinanceWrapperService>(typeof(IFinanceWrapperService).Name);  
  21. SaveInvoicesCommand = new DelegateCommand(ExecuteSaveInvoicesCommand);  
  22. }  
  23. private async void ExecuteSaveInvoicesCommand()  
  24. {  
  25. try  
  26. {  
  27. InvoiceHeader.LstInvoiceDetails = LstInvoiceDetails;  
  28. await _financeWrapperService.SaveInvoice(InvoiceHeader);  
  29. LoadData();  
  30. }  
  31. catch (Exception ex)  
  32. {  
  33. GlobalExceptionHandler.CatchException(ex);  
  34. }  
  35. }  
  36. private InvoiceHeaderDO _invoiceHeader;  
  37. public InvoiceHeaderDO InvoiceHeader  
  38. {  
  39. get  
  40. {  
  41. return _invoiceHeader;  
  42. }  
  43. set  
  44. {  
  45. _invoiceHeader = value;  
  46. OnPropertyChanged("InvoiceHeader");  
  47. }  
  48. }  
  49. private void InvoiceHeaderPropertyChanged(object sender, PropertyChangedEventArgs e)  
  50. {  
  51. var curentObject = sender as InvoiceHeaderDO;  
  52. if (InvoiceHeader == nullreturn;  
  53. InvoiceHeader.ValidateProperties();  
  54. switch (e.PropertyName)  
  55. {  
  56. case "CurrencyId":  
  57. var currencyObject = LstCurrency.FirstOrDefault(q => q.ID == curentObject.CurrencyId);  
  58. if (currencyObject != null)  
  59. {  
  60. curentObject.ExchangeRate = currencyObject.ExchangeRate;  
  61. }  
  62. break;  
  63. }  
  64. }