1
我在應用程序的最右側有一個按鈕。點擊時,我想在按鈕下方顯示一個菜單,但與其對齊。 (認爲谷歌鉻菜單)。與GTK右對齊的彈出式菜單#
這是我到目前爲止有:
protected virtual void HandleMenuClicked (object sender, System.EventArgs e)
{
Menu menu = new Menu();
menu.Add(new MenuItem("About"));
menu.ShowAll();
menu.Popup(null,null,MenuPosition,0,0);
}
private void MenuPosition(Menu menu, out int x, out int y, out bool pushIn)
{
_menuButton.ParentWindow.GetOrigin(out x, out y);
int menuWidth = 75; //need to look up actual width.
x += _menuButton.Allocation.X - menuWidth;
y += _menuButton.Allocation.Y + _menuButton.Allocation.Height;
pushIn = true;
}
的問題,這是我硬編碼菜單的寬度。如果添加更長的菜單條目,字體改變或主題改變,那麼對齊將是錯誤的。
我試圖尋找出菜單的寬度,如下所示:
int menuWidth = menu.Allocation.Width;
這不作爲菜單工作尚未擬定尚等配置寬度爲1