Click here to Skip to main content
15,896,154 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi all,
I am creating wpf project using MVVM pattern.
Please tell me how can i bind decimal value with TextBox control using mvvm.?
Thankyou
Posted
Comments
Sergey Alexandrovich Kryukov 13-Aug-14 1:30am    
This is not really a concern of MVVM.
—SA

Please see my comment to the question. Do you want to see binding in each and every piece of UI and data? :-)
No matter what you do, everything boils down to this:
C#
decimal value = //...
MyTextBox.Text = value.ToString();
// ...
if (decimal.TryParse(MyTextBox.Value, out value))
   // use value... :-)


—SA
 
Share this answer
 
v2
Set the Text property with a public property defined in ViewModel class. set the decimal value to that property binded with TextBox Control.
 
Share this answer
 
Please find the solution in this link
Bind Decimal Value in textbox[^]

also you can use string format as follows

HTML
<TextBox Text="{Binding TransactionDetails.TransactionAmount, Mode=TwoWay, 
UpdateSourceTrigger=PropertyChanged,StringFormat=N2}" Grid.Column="3" 
Grid.ColumnSpan="2" Grid.Row="5" x:Name="TextBoxAmount" />
 
Share this answer
 
v2

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