Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何右对齐Windows.Controls.ContextMenu菜单项中的加速器文本?_C#_.net_Wpf_.net 4.0_Contextmenu - Fatal编程技术网

C# 如何右对齐Windows.Controls.ContextMenu菜单项中的加速器文本?

C# 如何右对齐Windows.Controls.ContextMenu菜单项中的加速器文本?,c#,.net,wpf,.net-4.0,contextmenu,C#,.net,Wpf,.net 4.0,Contextmenu,在Win32 API中,制表符(\t)用于在菜单项(“Open\tCtrl+O”)中显示右对齐文本(如加速器/快捷方式)。在一个C#应用程序中,我有一个从System.Windows.Controls.ContextMenu派生的类,以类似的方式使用制表符似乎不能获得相同的结果;它实际上插入了一个选项卡,因此快捷方式看起来更像是居中对齐,而不是右对齐 我知道在.net中,\uu是用来代替Win32&的助记符下划线。\t是否有类似的替代品 编辑:上下文代码(不带ICommand实现) 内部类MyC

在Win32 API中,制表符(
\t
)用于在菜单项(
“Open\tCtrl+O”
)中显示右对齐文本(如加速器/快捷方式)。在一个C#应用程序中,我有一个从
System.Windows.Controls.ContextMenu
派生的类,以类似的方式使用制表符似乎不能获得相同的结果;它实际上插入了一个选项卡,因此快捷方式看起来更像是居中对齐,而不是右对齐

我知道在.net中,
\uu
是用来代替Win32
&
的助记符下划线。
\t
是否有类似的替代品

编辑:上下文代码(不带ICommand实现)

内部类MyContextMenu:ContextMenu,ICommand
{
私有只读字符串[]字列表;
公共MyContextMenu(字符串aWord)
{
var itemStyle=(Style)TryFindResource(“EditorContextMenuItem”);
wordList=GetMyWordList(aWord);
if(单词列表!=null)
{
for(int i=0;i0&&索引<16)
menuText=text+“\t_“+index.ToString(“x”);
其他的
menuText=“389;”+文本;
返回菜单文本;
}
}

将加速器文本设置为属性


另外,请注意文档页面中的备注:此属性不会将输入手势与菜单项相关联;它只是将文本添加到菜单项中。应用程序必须处理用户的输入以执行操作。有关如何将命令与菜单项关联的信息,请参阅命令。

您是否尝试过重新模板化上下文菜单项?发布一些代码会有帮助。在问题上发布一些代码。你能详细说明一下重新制作模板的想法吗?
internal class MyContextMenu : ContextMenu, ICommand
{
    private readonly string[] wordList;
    public MyContextMenu(string aWord)
    {
        var itemStyle = (Style) TryFindResource("EditorContextMenuItem");
        wordList = GetMyWordList(aWord);
        if (wordList != null)
        {
            for (int i = 0; i < wordList.Length; ++i)
            {
                string word = wordList[i];
                var item = new MenuItem
                                {
                                    Style = itemStyle,
                                    Header = BuildMenuText(i + 1, word),
                                    Command = this,
                                    CommandParameter = i
                                };
                this.Items.Add(item);
            }
        }
    }

    static private string BuildMenuText(int index, string text)
    {
        string menuText;
        if (index > 0 && index < 16)
            menuText = text + "\t_" + index.ToString("x");
        else
            menuText = "_" + text;

        return menuText;
    }
}