Entering Decimal Value In WPF TextBox Which is Binding By Double DataType By Without Delay

Double DataType Binding in WPF TextBox And Entering The Decimal Value Without Using Delay Properties of TextBox In WPF.

Sample Demo Adding Amount+charges=Total

Design With XAML And Class Uses for Properties.

XAML:

  1. <Grid>  
  2.     <Border BorderThickness="0" BorderBrush="#E3E3E3E3">  
  3.         <Grid Background="#fafafa">  
  4.             <Grid.RowDefinitions>  
  5.                 <RowDefinition></RowDefinition>  
  6.                 <RowDefinition ></RowDefinition>  
  7.                 <RowDefinition></RowDefinition>  
  8.             </Grid.RowDefinitions>  
  9.             <Grid.ColumnDefinitions>  
  10.                 <ColumnDefinition Width="15"></ColumnDefinition>  
  11.                 <ColumnDefinition></ColumnDefinition>  
  12.                 <ColumnDefinition></ColumnDefinition>  
  13.             </Grid.ColumnDefinitions>  
  14.             <Label Grid.Column="1" Height="50" Grid.Row="0">Amount</Label>  
  15.             <Label Grid.Column="1" Height="50" Grid.Row="1">Charges</Label>  
  16.             <Label Grid.Column="1" Height="50" Grid.Row="2">Total</Label>  
  17.             <TextBox Text="{Binding TransactionDetails.Amount, Mode=TwoWay,StringFormat=0{0.0}, UpdateSourceTrigger=PropertyChanged}" Grid.Column="2" Height="50" Grid.Row="0" Name="TextBox1"/>  
  18.             <TextBox Text="{Binding TransactionDetails.Charges, Mode=TwoWay,StringFormat=0{0.0}, UpdateSourceTrigger=PropertyChanged}" Grid.Column="2" Height="50" Grid.Row="1" Name="TextBox2"/>  
  19.             <TextBox Grid.Column="2" Height="50" Grid.Row="2" IsReadOnly="True">  
  20.                 <TextBox.Text>  
  21.                     <MultiBinding Converter="{wpf:MathConverter}" ConverterParameter="x+y" Mode="TwoWay">  
  22.                         <Binding Path="Text" ElementName="TextBox1" />  
  23.                         <Binding Path="Text" ElementName="TextBox2"/>  
  24.                     </MultiBinding>  
  25.                 </TextBox.Text>  
  26.             </TextBox>  
  27.         </Grid>  
  28.     </Border>  
  29. </Grid>  
Class:

  1. class Class1: INotifyPropertyChanged {  
  2.     public event PropertyChangedEventHandler PropertyChanged;  
  3.     private double _amount;  
  4.     private double _chrges;  
  5.     private double _total;  
  6.     public double Amount {  
  7.         get {  
  8.             return _amount;  
  9.         }  
  10.         set {  
  11.             _amount = value;  
  12.             Notify("Amount");  
  13.         }  
  14.     }  
  15.     public double Chrges {  
  16.         get {  
  17.             return _chrges;  
  18.         }  
  19.         set {  
  20.             _chrges = value;  
  21.             Notify("Chrges");  
  22.         }  
  23.     }  
  24.     public void Notify(string propertyName) {  
  25.         if (this.PropertyChanged != null) {  
  26.             this.PropertyChanged(thisnew PropertyChangedEventArgs(propertyName));  
  27.         }  
  28.     }  
  29. }