Click here to Skip to main content
15,886,518 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
XML
var resultIntradayBP = (from risk se in _abemodel.risks where se.description == RiskProfile select se.intradaybp).Single<decimal>();
           
            IntradayBP = Convert.ToDouble(resultIntradayBP);
Posted
Updated 16-Jan-11 8:54am
v3

Set IsReadOnly="True" to IsReadOnly="False". Don't forget to Addnew record.
 
Share this answer
 
Comments
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.

http://www.abhisheksur.com/2010/05/object-notifiers-using.html[^]

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
 
Comments
kayani29 16-Jan-11 14:56pm    
I have tested that too.. no success
Hi,
If your view model implements INotifyPropertyChanged , trigger the propertyChanged of 'IntradayBP' after setting 'IntradayBP' .Otherwise you should implement INotifyPropertyChanged in your view model.

Regards,
Vineeth
 
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