0

I'm still stuck.

Assume that I've got a user control with a button. And an event called damnIt_ButtonClicked. In the main window I want to emulate the control's lifetime like it is a modal dialog, although it's not.

I want to wrap everything into one method, it returns true if the Button on the control clicked.

  public bool Show() {

      var control = new ControlWithSingleButton();
      bool result;

      control.damnIt_ButtonClicked += (object sender, EventArgs args) =>
      {
            result = true;
      };

      MainWindowGrid.Children.Add(control);
      MainWindowGrid.Visibility = Visibility.Visible;


      return result;
  }

Now. As you see the problem is this method will return always false; But I need to return a result only when damnIt_ButtonClicked event fires. It means I have to put the thread on wait, till the user clicks button. Right? Or how it should be done. Help me please....

4

2 回答 2

0

You're going to need to re-architect your solution. Without knowing a broader scope of what you're trying to do, here's a possible solution.

private bool buttonResult;

public void Show() {

  var control = new ControlWithSingleButton();
  bool result;

  control.damnIt_ButtonClicked += (object sender, EventArgs args) =>
  {
        this.ProcessButtonClick();
  };

  MainWindowGrid.Children.Add(control);
  MainWindowGrid.Visibility = Visibility.Visible;

  }

private void ProcessButtonClick()
{
   this.buttonResult = true;
   //do whatever you would have before if Show had returned true
}
于 2010-08-04T20:21:17.123 回答
0

You know what? I give up!

I decided to make the control a window, although it was strictly prohibited in given specifications to use any other windows but the Main. Anyway it's gonna be a chromeless, borderless transparent window, so nobody can see the difference.

Thank you so much.

于 2010-08-05T13:33:54.677 回答