My today’s msdn-solve CodeClip is about porting a standard behavior of applications to Silverlight 4. When filling out a form (either in the web or in a .NET application or elsewhere) users tend to hit the <Return> key and hopefully the application deals with the data entries as intended. But how to implement this in a Silverlight environment?
The key is to use triggers from the Microsoft Expression SDK and automation peers. Triggers can be added to any elements in the XAML markup and listen to a given event. In the CodeClip a trigger is added to the “KeyDown” event of a TextBox. When the event occurs some code is triggered that checks if the pressed key is the <Return> key. If so, an automation peer simulates a click on a given button.
Voilà: default button behavior – at your service!