Click here to Skip to main content
15,666,844 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have written a code and bind a textbox to my username property in viewmodel.. When the window loads for the first time the textbox.text get updated but when i try to change the text from view model it does not get updated in textbox.text;

my xaml code for property is this

<TextBox Text="{Binding IntradayBP}" Height="23" HorizontalAlignment="Left" Margin="100,95,0,0" Name="textBox3" VerticalAlignment="Top" Width="120" IsReadOnly="True" />

and my code for that property in view model is this
var resultIntradayBP = (from risk se in _abemodel.risks where se.description == RiskProfile select se.intradaybp).Single<decimal>();
            IntradayBP = Convert.ToDouble(resultIntradayBP);
Updated 16-Jan-11 8:54am

Set IsReadOnly="True" to IsReadOnly="False". Don't forget to Addnew record.
Share this answer
kayani29 16-Jan-11 14:34pm    
I changed that property to IsReadOnly to True .. still no success
Аslam Iqbal 16-Jan-11 14:36pm    
Read my answer carefully.
kayani29 16-Jan-11 14:49pm    
What do you mean by Addnew record??
Аslam Iqbal 16-Jan-11 15:05pm    
After you insert or update a record then you have to call addnew_record before inserting new one.
To get a textbox updated when a property changes its value, implement your property from INotifyPropertyChanged.[^]

You should also note, binding will not work if you explicitly set TextBox.Text somewhere in code behind.

Try removing any code that directly accesses your textbox, and update your text only from your ViewModel.

I hope it will work. :rose:
Share this answer
If Aslam Iqbal answer dosen't work try setting the binding mode to two way. Something like:

<textbox text="{Binding IntradayBP, Mode=TwoWay}" ....=""></textbox>
Share this answer
kayani29 16-Jan-11 14:56pm    
I have tested that too.. no success
If your view model implements INotifyPropertyChanged , trigger the propertyChanged of 'IntradayBP' after setting 'IntradayBP' .Otherwise you should implement INotifyPropertyChanged in your view model.

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