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.
精彩评论