TextBox.Text没有第二次更新 [英] TextBox.Text not getting updated on second time

查看:101
本文介绍了TextBox.Text没有第二次更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经编写了代码,并将文本框绑定到viewmodel中的username属性.当窗口第一次加载时,textbox.text得到更新,但是当我尝试从视图模型中更改文本时,它没有更新在textbox.text;

我的财产xaml代码是这个

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);

推荐答案

将IsReadOnly ="True"设置为IsReadOnly ="False".不要忘记添加新记录.
Set IsReadOnly="True" to IsReadOnly="False". Don''t forget to Addnew record.


要在属性更改其值时更新文本框,请从INotifyPropertyChanged实现属性.

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

您还应该注意,如果您在后面的代码中的某个位置显式设置了TextBox.Text,则绑定将不起作用.

尝试删除任何直接访问您的文本框的代码,并仅从ViewModel中更新文本.

我希望它能起作用. :rose:
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:


如果Aslam Iqbal回答不起作用,请尝试将绑定模式设置为两种方式.像这样的东西:

If Aslam Iqbal answer dosen''t work try setting the binding mode to two way. Something like:

<textbox text="{Binding IntradayBP, Mode=TwoWay}" ....=""></textbox>


这篇关于TextBox.Text没有第二次更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆