I’m currently working on some code that handles keyboard shortcuts in my Silverlight 4 application. I want to create a manage window where users can define custom keyboard shortcuts if they do not want to use the default ones. However some keys have a different translation in some languages (e.g. Home, Del, …). Of course I want to translate those texts so that every user understands the keyboard shortcuts correctly.
Is there something like a built-in translation for something like this? I’m thinking of something like the way DateTime behaves. If I work with DateTimes the texts for days or months are automatically defined through the systems Culture settings.
string dateTimeTest = DateTime.Now.ToLongDateString();
On a German system this results in the text “Freitag, 20. Juli 2012”.
Is there something comparable like this available for keys as well? Or do I have to translate all needed keys manually?
Thanks in advance!
As with most language support, you have to do this yourself in Silverlight. Of course, there are ways to make that easier.
If you’re app is running out-of-browser (OOB), in Silverlight 4, you could deploy a COM object that wraps the native call to
GetKeyNameText; in Silverlight 5, OOB or elevated in-browser app, you could P/Invoke it directly.However, if you are running inside the browser without elevated privileges, your options are greatly diminished. I am not aware of any libraries (commercial or otherwise) that provide this feature, so you’re going to have to create your own localizable resources and associated methods to achieve this.
You may find the W3C guidance on accessibility in Silverlight to be a useful resource.