开发者

Property binding in MVVM

开发者 https://www.devze.com 2023-04-10 05:01 出处:网络
my cpde in ModelView : public Boolean EnableTextBox { get; set; } public CustomerAccountVM() { this.EnableTextBox = false;

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

精彩评论

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

关注公众号