简体   繁体   中英

INotifyPropertyChange does not update converter-based values?

I have an image with source set by a ValueConverter :

<Image Source="{Binding Converter={StaticResource siConv}}" Width="16" Height="16"/>

When the bound object raises a PropertyChanged event (from INotifyPropertyChanged ), the image does not change. I assume it is because WPF doesn't know what fields the converter looks at.

How do I tell WPF to rebind/rerun this converter when a certain property changes?

路径很重要:

<Image Source="{Binding Converter={StaticResource siConv}, ConverterParameter=yourproperty, Path=yourproperty, UpdateSourceTrigger=PropertyChanged}"  Width="16" Height="16"/>

The answer here was to use data triggers, not value converters. The trigger is bound directly to the property, and picks up the propertychanged event. Also, saves writing a bunch of one-time value converters.

And if you really intent on writing a ValueConverter, may be use a MultiValueConverter with all the values that you want the WPF framework to monitor. Any changes to those values, and the framework would update the value it is binded to.

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