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:
<Grid>
<Border BorderThickness="0" BorderBrush="#E3E3E3E3">
<Grid Background="#fafafa">
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition ></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="15"></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<Label Grid.Column="1" Height="50" Grid.Row="0">Amount</Label>
<Label Grid.Column="1" Height="50" Grid.Row="1">Charges</Label>
<Label Grid.Column="1" Height="50" Grid.Row="2">Total</Label>
<TextBox Text="{Binding TransactionDetails.Amount, Mode=TwoWay,StringFormat=0{0.0}, UpdateSourceTrigger=PropertyChanged}" Grid.Column="2" Height="50" Grid.Row="0" Name="TextBox1"/>
<TextBox Text="{Binding TransactionDetails.Charges, Mode=TwoWay,StringFormat=0{0.0}, UpdateSourceTrigger=PropertyChanged}" Grid.Column="2" Height="50" Grid.Row="1" Name="TextBox2"/>
<TextBox Grid.Column="2" Height="50" Grid.Row="2" IsReadOnly="True">
<TextBox.Text>
<MultiBinding Converter="{wpf:MathConverter}" ConverterParameter="x+y" Mode="TwoWay">
<Binding Path="Text" ElementName="TextBox1" />
<Binding Path="Text" ElementName="TextBox2"/>
</MultiBinding>
</TextBox.Text>
</TextBox>
</Grid>
</Border>
</Grid>Class:class Class1: INotifyPropertyChanged {
public event PropertyChangedEventHandler PropertyChanged;
private double _amount;
private double _chrges;
private double _total;
public double Amount {
get {
return _amount;
}
set {
_amount = value;
Notify("Amount");
}
}
public double Chrges {
get {
return _chrges;
}
set {
_chrges = value;
Notify("Chrges");
}
}
public void Notify(string propertyName) {
if (this.PropertyChanged != null) {
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}