Click here to Skip to main content
15,881,757 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to show the numbers in TextBox with thousand separator without binding it and without programmatically

Just in XAML

like this example : 123456 => 123,456 or 1000000000 => 1,000,000,000

What I have tried:

Also this line in XAML have error
<TextBox x:Name="text_main2" Text="{Binding StringFormat={}{0:N0}}"  VerticalAlignment="Top" Width="303"/>

And I don't no can I do this work in TextBoxMask :
<xctk:MaskedTextBox Mask="0000"  PromptChar=" " x:Name="txtname"  HorizontalContentAlignment="Right" HorizontalAlignment="Left" Height="22" Margin="512,296,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="152"/>

Please help
Posted
Updated 31-Jul-21 8:29am
v3
Comments
Chris Copeland 23-Jul-21 4:19am    
I don't understand this question, what do you mean without binding it and without programmatically? How are you planning on actually putting the number into the textbox? In WPF the standard model would be to use binding, but in your first example you've not provided a path to bind to.

If you're not going to bind to a property (which IMHO is stupid and goes against everything WPF stands for), you have to format the values yourself in code-behind.
 
Share this answer
 
You can use ContentStringFormat property, or you can use a binding. You can also even use a content template... I know, you don't want bindings, but even if you don't want to bind to some property's value, you can still use a binding just for formatting.

Your current binding lacks a property path, which would be valid if you were inside a data template or if you had set a suitable DataContext, but a binding always assumes you are getting a value from somewhere (from another control, from a resource, from a property, from a static member, etc.).

To give you a proper answer, we need to know more about what you need to do. For example, where do you want to get the number from?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900