开发者

WPF Converter problem

开发者 https://www.devze.com 2022-12-10 07:19 出处:网络
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:

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 u开发者_运维问答pdate 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号