开发者

Property binding in MVVM

my cpde in ModelView :

 public Boolean EnableTextBox { get; set; }

 public CustomerAccountVM()
 {

     this.EnableTextBox = false;

      //...
 }

code in View: XAML :

   <TextBox Text="{Binding Path=IdCustomer, Mode=开发者_C百科Default}" IsEnabled="{Binding Path=EnableTextBox,Mode=Default}" />

Why the code does not work?

no answer ?


You're not publishing the fact that the Enable property has been updated.

You need to implement the INotifyPropertyChanged interface and change your property to be:

private Boolean _enableTextBox;
public Boolean EnableTextBox
{
    get { return _enableTextBox; }
    set
    {
        _enableTextBox = value;
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(info));
        }
    }
 }

You should wrap the PropertyChanged code in a method so you're not repeating yourself.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜