Search code examples
wpfxamlblend

EventTrigger fails to trigger on IsEnabledChanged


I have a custom control inherited from UserControl that I am enabling/disabling via a binding and trying to use an EventTrigger for IsEnabledChanged to cause a ChangePropertyAction behavior to execute.

            <local:StockmarketFilecard x:Name="StockmarketReport2" VerticalAlignment="Bottom" Panel.ZIndex="0" IsEnabled="{Binding DataContext.BankReportEnabled, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Window}}">
                <Interactions:Interaction.Triggers>
                    <Interactions:EventTrigger EventName="IsEnabledChanged">

                        <Interactions:ChangePropertyAction PropertyName="MaxHeight"  Value="100"/>
                    </Interactions:EventTrigger>
                </Interactions:Interaction.Triggers>
            </local:StockmarketFilecard>

Interactions uses the http://schemas.microsoft.com/xaml/behaviors namespace.

Problem is that the ChangePropertyAction is not executed despite the control visibly becoming enabled/disabled. I have tested adding a code-behind eventhandler for IsEnabledChanged on the control and it is called as expected. I have also tested triggering on the Loaded event to verify that the action is correct and the control changes as expected.

What am I missing to get the EventTrigger to trigger on IsEnabledChanged?


Solution

  • What am I missing to get the EventTrigger to trigger on IsEnabledChanged?

    The fact that the EventTrigger only handles routed events and IsEnabledChanged is not a routed event.

    You may either set the MaxHeight property in an event handler in the code-behind of the view, or implement an attached behaviour as suggested here.