1

Let's say that, in WPF, I have a following user control:

public partial class FlipButton : UserControl
{
    private Boolean _isOn = false;
}
public Boolean isOn
{
    get { return _isOn; }
    set { if (value) FlipBtn.Background = onColor;
          else FlipBtn.Background = offColor; _isOn = value; }
}
private void FlipBtn_Click(object sender, RoutedEventArgs e)
{
    isOn = !isOn;
}

with a corresponding <Button Name="FlipBtn" Click="FlipBtn_Click"> inside.

Now, I want to create a FlipButtonGroup, which holds a collection of those buttons laid out in a grid and has an internal collection of buttons in "enabled" state. It would have to update whenever a button is clicked, and there's my question: can I somehow guarantee that updating the isOn value will take place before the FlipButtonGroup handles the click?

BartoszKP
  • 34,786
  • 15
  • 102
  • 130
Maciej Stachowski
  • 1,708
  • 10
  • 19

1 Answers1

0

Please see Order of event handler execution. You may be able to rely on them being called in the order registered. This could break in the future though.

Community
  • 1
  • 1
David Arno
  • 42,717
  • 16
  • 86
  • 131