Note that there are some explanatory texts on larger screens.

plurals
  1. PONeed work-around for overriding RoutedUICommand.Text property
    text
    copied!<p>I have a static Command class like this (but with many more commands):</p> <pre><code>class GuiCommands { static GuiCommands() { addInterface = new RoutedUICommand(DictTable.getInst().getText("gui.addInterface"), "addInterface", typeof(GuiCommands)); removeInterface = new RoutedUICommand(DictTable.getInst().getText("gui.removeInterface"), "removeInterface", typeof(GuiCommands)); } public static RoutedUICommand addInterface { get; private set; } public static RoutedUICommand removeInterface { get; private set; } } </code></pre> <p>It should use my dictionary to get the texts in the right language, which doesn't work, because my dictionary isn't initialized when the static constructor is executed.</p> <p>My first attempt was to create a new command-class which derives from RoutedUICommand, override the Text property and call the dict in the get method. But the Text property isn't virtual and neither is the GetText()-Method it calls.</p> <p>The only thing i can think of is provide a static initialize method in this class that translates all the dict-keys. But this is not very clean IMHO because i have to name every command once again like this</p> <pre><code>addInterface.Text = DictTable.getInst().getText(addInterface.Text); </code></pre> <p>and if i forget to name one, there won't be an error, just no translation. I don't even like that i have to name the command twice in this class and once again in the XAML commandbindings.</p> <p>Do you have any ideas how this can be solved more elegantly?</p> <p>I like RoutedUICommands much, but like this they're useless to me. Why couldn't Microsoft add the little word 'virtual' a little more often?? (or make it default like JAVA does?!)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload