'How to cancel hiding a Devexpress flyoutpanel according to a condition?

I have a FlyoutPanel and I want to hide it according to a condition.
For example: I want to hide it when a counter is equal to 3.
What I have tried is:

private void flyoutPanel1_BeforeHide(object sender, CancelEventArgs e)
{
    if (globalCounter == 3)
        flyoutPanel1.HideBeakForm();
    else
    {
        globalCounter++;
        e.Cancel = true;
    }
}

The problem is: flyoutPanel1_BeforeHide only called once, after it sees e.Cancel=true; it will never called again.
I want this method to be called whenever I try to hide the flyoutpanel.
Is the problem is with my code or its a bug with Devexpress?

Iam using c# winforms with the latest version of Devexpress Winforms



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source