WPF: A TextBox that has an event that fires when the Enter Key is pressed
Instead of attaching a PreviewKeyUp event with each TextBox in my app and checking if the pressed key was an Enter key and then do an action, I decided to implement extended version of a TextBox that includes a DefaultAction event that fires when an Enter Key is pressed in a TextBox . What I did was basically create a new Class that extends from TextBox with a public event DefaultAction , like such: public class DefaultTextBoxControl:TextBox { public event EventHandler<EventArgs> DefaultAction = delegate { }; public DefaultTextBoxControl() { PreviewKeyUp += DefaultTextBoxControl_PreviewKeyUp;