In my main window, I have a child control(user control) which contains a text box . How can I handle the textchange event of the text box of child control in main(parent) window.
Please provide me some example with code as I am new to routing of events.
You should just be able to hook the event from the parent control. But since your parent control doesn’t have a
TextChangedevent of its own, you’ll need to use attached-property syntax:and in your codebehind:
You don’t have to put the
TextBox.TextChanged=on theWindowspecifically — just any control that’s a parent of theTextBox, i.e., any control that’s a parent of yourUserControl. The event will bubble up to each parent in turn, all the way up to the top-levelWindow, and can get handled anywhere along the way.(Note that if anyone hooks the event and sets
e.Handled = true, the event won’t bubble past that point. Useful to know if you have handlers at multiple levels.)