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
- <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>
- <controls:ProTextBox Grid.Row="0" Grid.Column="3" HorizontalAlignment="Stretch" TabIndex="3" Margin="5,0,0,0" Height="25"
- IsEnabled="{Binding InvoiceHeader.IsEnabled,UpdateSourceTrigger=PropertyChanged}"
- Text="{Binding InvoiceHeader.CustomerName,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}">
- </controls:ProTextBox>
- <controls:ProTextBlock Text="Address : " Grid.Row="1" Grid.Column="2" Margin="5,0,0,0" HorizontalAlignment="Left" VerticalAlignment="Center" ></controls:ProTextBlock>
- <controls:ProTextBox Grid.Row="1" Grid.Column="3" Margin="5,0,0,0" TabIndex="4"
- IsEnabled="{Binding InvoiceHeader.IsEnabled,UpdateSourceTrigger=PropertyChanged}"
- VerticalAlignment="Center" VerticalContentAlignment="Center"
- HorizontalAlignment="Stretch" Height="25"
- Text="{Binding InvoiceHeader.CustomerAddress,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}">
- </controls:ProTextBox>
- <controls:ProTextBlock Text="Phone :" Grid.Row="2" Grid.Column="2" Margin="5,0,0,0" HorizontalAlignment="Left" ></controls:ProTextBlock>
- <controls:ProTextBox Grid.Row="2" Grid.Column="3" TabIndex="5" Margin="5,0,0,0"
- IsEnabled="{Binding InvoiceHeader.IsEnabled,UpdateSourceTrigger=PropertyChanged}"
- HorizontalAlignment="Stretch" Height="25" Text="{Binding InvoiceHeader.CustomerPhone,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}">
- </controls:ProTextBox>
- <controls:ProImageButton ImageType="Add"
- Command="{Binding AddInvoiceDetailsCommand}" Style="{DynamicResource ImageButton}"
- Background="{x:Null}"
- IsEnabled="{Binding InvoiceHeader.IsEnabled,UpdateSourceTrigger=PropertyChanged}"
- BorderThickness="0" />
And properties of buttons are
- private bool? _isFinalized;
- public bool? IsFinalized
- {
- get { return this._isFinalized; }
- set { this.SetProperty(ref this._isFinalized, value, () => this.IsFinalized); }
- }
- public bool IsEnabled { get { return !Convert.ToBoolean(IsFinalized); } }
- private string _customerName;
- [Required]
- public string CustomerName
- {
- get { return this._customerName; }
- set { this.SetProperty(ref this._customerName, value, () => this.CustomerName); }
- }
- private string _customerAddress;
- [Required]
- public string CustomerAddress
- {
- get { return this._customerAddress; }
- set { this.SetProperty(ref this._customerAddress, value, () => this.CustomerAddress); }
- }
- private string _customerPhone;
- [Required]
- public string CustomerPhone
- {
- get { return this._customerPhone; }
- set { this.SetProperty(ref this._customerPhone, value, () => this.CustomerPhone); }
- }
In view model i have a constructor
- private InvoiceHeaderDO _invoiceHeader;
- public InvoiceHeaderDO InvoiceHeader
- {
- get
- {
- return _invoiceHeader;
- }
- set
- {
- _invoiceHeader = value;
- OnPropertyChanged("InvoiceHeader");
- }
- }
- private ILookupWrapperService _lookupWrapperService;
- private IFinanceWrapperService _financeWrapperService;
- public ICommand SaveInvoicesCommand { get; set; }
- public InvoiceDetailsViewModel()
- {
- _lookupWrapperService = ServiceLocator.Current.GetInstance<ILookupWrapperService>(typeof(ILookupWrapperService).Name);
- _financeWrapperService = ServiceLocator.Current.GetInstance<IFinanceWrapperService>(typeof(IFinanceWrapperService).Name);
- SaveInvoicesCommand = new DelegateCommand(ExecuteSaveInvoicesCommand);
- }
- private async void ExecuteSaveInvoicesCommand()
- {
- try
- {
- InvoiceHeader.LstInvoiceDetails = LstInvoiceDetails;
- await _financeWrapperService.SaveInvoice(InvoiceHeader);
- LoadData();
- }
- catch (Exception ex)
- {
- GlobalExceptionHandler.CatchException(ex);
- }
- }
- private InvoiceHeaderDO _invoiceHeader;
- public InvoiceHeaderDO InvoiceHeader
- {
- get
- {
- return _invoiceHeader;
- }
- set
- {
- _invoiceHeader = value;
- OnPropertyChanged("InvoiceHeader");
- }
- }
- private void InvoiceHeaderPropertyChanged(object sender, PropertyChangedEventArgs e)
- {
- var curentObject = sender as InvoiceHeaderDO;
- if (InvoiceHeader == null) return;
- InvoiceHeader.ValidateProperties();
- switch (e.PropertyName)
- {
- case "CurrencyId":
- var currencyObject = LstCurrency.FirstOrDefault(q => q.ID == curentObject.CurrencyId);
- if (currencyObject != null)
- {
- curentObject.ExchangeRate = currencyObject.ExchangeRate;
- }
- break;
- }
- }