KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm trying to create a WPF MarkupExtension class that provides translated text from my text translation class. The translation stuff works great, but requires a static method call with a text key to return the translated text. Like this: ImportLabel.Text = Translator.Translate("import files"); // will be "Dateien importieren" in de or "Import files" in en Its speciality is that it accepts a counting value to provide better wordings. ImportLabel.Text = Translator.Translate("import n files", FileCount); // will be "Import 7 files" or "Import 1 file" Another example: If something takes yet 4 minutes, it's a different word than if it only takes one minute. If a text key "minutes" is defined as "Minuten" for any number and as "Minute" for a count of 1, the following method call will return the right word to use: Translator.Translate("minutes", numberOfMinutes) // will be "minute" if it's 1, and "minutes" for anything else Now in a WPF application, there's a lot of XAML code and that contains lots of literal texts. To be able to translate them without getting nuts, I need a markup extension which I can pass my text key and that will return the translated text at runtime. This part is fairly easy. Create a class inheriting from MarkupExtension, add a constructor that accepts the text key as argument, store it in a private field, and let its ProvideValue method return a translation text for the stored key. My real problem is this: How can I make my markup extension accept a counting value in such a way that it's data-bound and the translation text will update accordingly when the count value changes? It should be used like this: <TextBlock Text="{t:Translate 'import files', {Binding FileCount}}"/> Whenever the binding value of FileCount changes, the TextBlock must receive a new text value to reflect the change and s
Tags (comma-separated)
Save Edits
Cancel