Search code examples
wpfxamlavaloniaui

In WPF - XAML is there a way to bind to a property change behaviour without using UpdateSourceTrigger?


I'm trying to code some behaviours in WPF. Consider the following code snippet:

<Button IsEnabled="{Binding Path=ButtonsAreEnabled, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}">

Is there a way for me to achieve the behaviour: UpdateSourceTrigger=PropertyChanged} without using UpdateSourceTrigger?

I'm attempting to port some existing WPF definitions into Avalonia UI and Avalonia does not currently support UpdateSourceTrigger.

How would I do this?

Thanks,JohnB


Solution

  • The combination Mode=OneWay and UpdateSourceTrigger=PropertyChanged is pointless.

    UpdateSourceTrigger only has an effect in TwoWay or OneWayToSource Bindings, where it controls when exactly the source property of a Binding is updated.

    Besides that, setting Mode=OneWay is redundant, because the IsEnabled property binds OneWay by default.

    So your Binding expression should simply be this:

    <Button IsEnabled="{Binding Path=ButtonsAreEnabled}">
    

    Or even shorter:

    <Button IsEnabled="{Binding ButtonsAreEnabled}">