WPF:指定内置命令标签的语言
我使用内置的 ApplicationCommands
创建菜单:
<Menu DockPanel.Dock="Top">
<MenuItem Header="_Datei">
<MenuItem Command="ApplicationCommands.New" />
<MenuItem Command="ApplicationCommands.Open" />
<MenuItem Command="ApplicationCommands.Save" />
<MenuItem Command="ApplicationCommands.SaveAs" />
<Separator />
<MenuItem Header="Been_den" Command="{StaticResource SchliessenCommand}" />
</MenuItem>
</Menu>
ApplicationCommands
显示的文本因系统语言而异:在英语 Windows 7 上运行,ApplicationCommands.New
显示为“New”,而在德语 Windows 7 上显示为“Neu”。
由于应用程序的其余部分未本地化,我希望应用程序命令始终以德语显示。有没有办法无需手动设置每个菜单项的标题
?
I'm using the built-in ApplicationCommands
to create a menu:
<Menu DockPanel.Dock="Top">
<MenuItem Header="_Datei">
<MenuItem Command="ApplicationCommands.New" />
<MenuItem Command="ApplicationCommands.Open" />
<MenuItem Command="ApplicationCommands.Save" />
<MenuItem Command="ApplicationCommands.SaveAs" />
<Separator />
<MenuItem Header="Been_den" Command="{StaticResource SchliessenCommand}" />
</MenuItem>
</Menu>
The text displayed by the ApplicationCommands
differs depending on the system language: Running on an English Windows 7, ApplicationCommands.New
displays as "New", whereas it displays as "Neu" on a German Windows 7.
Since the rest of the application is not localized, I want the application commands to always display in German language. Is there a way to do that without manually setting the Header
of each MenuItem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于该应用程序未本地化,您可以尝试始终将语言设置为德语;也就是说,
CultureInfo.CurrentUICulture
,它通常是从操作系统继承的(在打开任何窗口之前在应用程序启动或类似的操作中设置它)。Since the application isn't localized, you can try to always set the language to german; that is,
CultureInfo.CurrentUICulture
, which is normally inherited from the OS (set it in application startup or something like that, before any windows are opened).您应该使用绑定并将命令作为绑定对象进行操作 (RelayCommands) 以避免对不同命令的标头进行硬编码。
You should use bindings and manipulate your commands as bind objects (RelayCommands) to avoid the hardcoding of the headers of your different commands.