简体   繁体   中英

PropertyDescriptor.AddValueChanged handler will not be executed with empty or white spaces string

I am using a propertyDescriptor to attach a handler on each properties of an instance. When one of these properties change, the handler method will be called except in one case (here's the problem) : when the value is a string and this string is empty or contains only white spaces.

I must perform this case to update IsEnabled property of my Save button.

foreach (PropertyDescriptor propertyDescriptor in TypeDescriptor.GetProperties(this.MyInstance))
{
    propertyDescriptor.RemoveValueChanged(this.MyInstance, this.MyMethod);
}

For example, when i edit the first name of an user and remove his first name, my save button must be disabled.

I found a new behavior.

All properties are used with bindings in a WPF application. MyMethod is called only if the UpdateSourceTrigger property is set to LostFocus. With PropertyChanged value, it doesn't. For some properties, I must used the PropertyChanged value : for dynamic ValidationRules in exemple.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM