Carlo
Carlo

Reputation: 25959

WPF Converter problem

So I have an object that implements INotifyPropertyChanged, and I have a property that when it changes, it call the PropertyChanged event all right, but when I use a converter like this:

        <Image Grid.Column="0">
            <Image.Source>
                <Binding Path="IsInstrumentStatusOk" UpdateSourceTrigger="PropertyChanged">
                    <Binding.Converter>
                        <converters:BooleanToImageConverter 
                            ImagePathIfFalse="/Images/InstrumentStatusBar/Instrument_Status_Alarm.png"
                            ImagePathIfTrue="/Images/InstrumentStatusBar/Instrument_Status_OK.png" />
                    </Binding.Converter>
                </Binding>
            </Image.Source>
        </Image>

For some reason it doesn't update it, and it doesn't call the converter. If I use it like normally

Source="{Binding MyProperty, Converter={StaticResource MyConverter}}"

It works, but I don't want to use it like that because I have a bunch of converters that I want to use with different images. Any idea why it doesn't update?

Thanks.

Upvotes: 1

Views: 690

Answers (1)

Drew Marsh
Drew Marsh

Reputation: 33379

You're setting UpdateSourceTrigger="PropertyChanged" in your XAML. This means when the target property changes the value should update back to the source. Obviously nothing is ever changing the Image::Source property.

Just remove the UpdateSourceTrigger setting altogether and you should be fine.

Upvotes: 2

Related Questions