简体   繁体   中英

How can I add 20% to a textbox value in C# WPF

In my WPF application I want a textbox that will add on a 20% to the users input value.

For example if users input is £85.00 then it should show £102.00.

How can I achieve this? Thanks.

    <TextBox LostFocus="JobPrice_LostFocus" materialDesign:HintAssist.Hint="Price" Width="250" Name="JobPrice" PreviewTextInput="JobPrice_PreviewTextInput" />

You can try this c# code:

private void TextBox1_LostFocus(object sender, RoutedEventArgs e)
    { 
        decimal CalculatedPrice = decimal.Parse(TextBox1.Text) * 20 / 100 + decimal.Parse(TextBox1.Text);
        TextBox1.Text = CalculatedPrice.ToString();            
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM