Hello,
Welcome to our Microsoft Q&A platform!
I want to notify property IsEnbaled when Student.Name is change when the Editor text is empty for ex.
You can use PropertyChanged
event to notify IsEnabled
property in StudentViewModel
when Student.Name
is changed like following code.
public class StudentViewModel: INotifyPropertyChanged
{
public Student student { get; set; }
bool _isEnabled = false;
public bool IsEnabled
{
get
{
return _isEnabled;
}
set
{
if (_isEnabled != value)
{
_isEnabled = value;
OnPropertyChanged("IsEnabled");
}
}
}
public StudentViewModel()
{
student = new Student() { Name="test1" };
student.PropertyChanged += Student_PropertyChanged;
}
private void Student_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == "Name")
{
IsEnabled = true;
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
I make an test with Entry
and Editor
, When I change the text in the Entry
, Editor
's IsEnabled will be changed from false to true.
<Entry Text="{Binding student.Name}"></Entry>
<Editor Text="Enditor" IsEnabled="{Binding IsEnabled}"></Editor>
Best Regards,
Leon Lu
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.