locked
handle event from a usercontrol textchange?

    Question

  • Here is the scenario.  I have a stackpanel called 'stack'.  There is a button for the user to push and a usercontrol called 'user' will be added to stack.  user has a textbox in there called 'text'.  How do I detect textchange inside text to fire event in page that holds stack?
    • Edited by RandyPete Saturday, April 26, 2014 12:59 PM
    Saturday, April 26, 2014 12:16 PM

Answers

  • The user control (UC) is opaque to its container, so the container cannot directly interact with the controls inside the user control. The user control needs to interact with them. The user control can then provide its own properties and events to the container. It can forward out any properties it wants to expose and they'll become part of the UC's contract.

    It's a bit of a hack, but the UC can also expose the TextBox via a property and the container can party on it through that.

    --Rob

    • Marked as answer by RandyPete Monday, April 28, 2014 6:01 PM
    Saturday, April 26, 2014 5:05 PM
    Owner
  • OOOOOhhhhhhhhhh

    So, I experimented around and figured out how to do this.

    In the usercontrol textbox, put x:FieldModifier = "public".  After this, the textbox is completely accessible by the containing page... and the sky is the limit.

    • Marked as answer by RandyPete Monday, April 28, 2014 6:01 PM
    Monday, April 28, 2014 6:00 PM

All replies

  • The user control (UC) is opaque to its container, so the container cannot directly interact with the controls inside the user control. The user control needs to interact with them. The user control can then provide its own properties and events to the container. It can forward out any properties it wants to expose and they'll become part of the UC's contract.

    It's a bit of a hack, but the UC can also expose the TextBox via a property and the container can party on it through that.

    --Rob

    • Marked as answer by RandyPete Monday, April 28, 2014 6:01 PM
    Saturday, April 26, 2014 5:05 PM
    Owner
  • OOOOOhhhhhhhhhh

    So, I experimented around and figured out how to do this.

    In the usercontrol textbox, put x:FieldModifier = "public".  After this, the textbox is completely accessible by the containing page... and the sky is the limit.

    • Marked as answer by RandyPete Monday, April 28, 2014 6:01 PM
    Monday, April 28, 2014 6:00 PM