开发者

C# wpf - MenuItem Header that loads from xml file (with accelerator [alt clicking] shortcut)

I am trying to create a Multi-Language WPF program that开发者_如何学Go will load it's languages from an xml path, though i'm having problem loading a MenuItem translation and give it it's accelerator.

Here's the main code:

<Window.Resources>
    <XmlDataProvider x:Key="Lang" Source="/lang/english.xml" XPath="Language/MainWindow"/>
</Window.Resources>
<MenuItem Header="{Binding Source={StaticResource Lang}, XPath=MenuItems/MenuItemFile/@Header}"/>

Here's how my language file looks like:

<?xml version="1.0" encoding="utf-8" ?>
<Language>
    <MainWindow>
    <MenuItems>
        <MenuItemFile Header="File" />
    </MenuItems>
    </MainWindow>
</Language>

My problem is: in this state of the language file it's all ok, but when i am trying to change the Header of MenuItemFile to "_File" (to give it an accelerator option), the program starts and gives the File menu the Header "_File" and not "File" (and an accelerator).

Thanks in advanced, Din.


Bind to AccessText instead of binding to Header directly:

<MenuItem>
    <MenuItem.Header>
        <AccessText Text="{Binding Source={StaticResource Lang}, XPath=MenuItems/MenuItemFile/@Header}"/>
    </MenuItem.Header>
</MenuItem>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜