2
在Win32 API中,製表符(\t
)用於顯示菜單項("Open\tCtrl+O"
)中的右對齊文本(如加速器/快捷方式)。在C#應用程序中,我有一個從System.Windows.Controls.ContextMenu
派生的類,並且似乎以類似方式使用製表符不會達到相同的結果;它實際上插入了一個選項卡,因此該快捷方式看起來比右對齊更加居中對齊。如何在Windows.Controls.ContextMenu menuitem中右對齊加速器文本?
我知道使用.net _
來代替Win32 &
的助記符下劃線。是否有類似\t
的替代品?
編輯:上下文代碼(不執行的ICommand)
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;
}
}
您是否嘗試過重新模板化ContextMenu項目?發佈一些代碼會很有幫助。 – decyclone 2010-12-09 06:21:48