UWP: Displaying formatted text in a TextBox Control

The entry you make in a text box control is of data type text and sometimes you need to format it as a currency with thousands separator while displaying.

Also, if the number of decimal places you enter is more than 2, you need to round it up to 2 in the output.

How do you code this in a UWP app?

Create a UWP page starting from a Blank UWP project with three controls as shown.




There are two text boxes and a button. You enter a number in the top textbox (txt1) and click the button, the formatted currency will be displayed in the bottom textbox(txt2).


The app displays as shown.

Now provide for a click event for the button and insert code as shown:

Convert_1

The string entered in txt1 is converted to data-type double, it is then 'rounded'. The rounded number is then formatted to show the currency symbol and the 1000's place delimiter you find, for example in Excel formatting.


Here is the app after entering a number and clicking the button.







Comments

eÄŸitim said…
https://www.uwptutorials.com/uwpxamlcontrols.html

Popular posts from this blog

Handling AppManifest Validation error

UWP: XAML's ComboBox Control -Part 1