向WPF Ribbon添加新項目我正在使用WPF Office功能區,並且我有一個內容視圖,當該視圖變爲活動狀態時,我希望將新項目添加到功能區。我有添加一個新的RibbonCommand以及一個新的RibbonButton到我想要的組的代碼,但添加它時沒有任何反應。但是,如果我用按鈕添加一個新組,它會很好地被正確綁定。有沒有一些方法可以讓它更新,我錯過了?我試過UpdateLayout(),它也不起作用。我真的很想嘗試,並避免每次查看更改時重建所有組。通過代碼
作品:
public void InjectItems(IView view)
{
var ribbonCommands = ProcessRibbonCommands(view.GetViewModel().Tasks, view.GetType());
var group = new RibbonGroup();
group.Command = new RibbonCommand() { LabelTitle = "Group Test" };
foreach (RibbonCommand command in ribbonCommands)
{
shell.MainRibbon.Resources.Add(command.Name, command);
group.Controls.Add(new RibbonButton { Command = command });
}
shell.MainRibbon.SelectedTab.Groups.Add(group);
}
不起作用:
public void InjectItems(IView view)
{
var ribbonCommands = ProcessRibbonCommands(view.GetViewModel().Tasks, view.GetType());
var group = shell.MainRibbon.SelectedTab.Groups[0]; //I have a default group, will fix later
foreach (RibbonCommand command in ribbonCommands)
{
shell.MainRibbon.Resources.Add(command.Name, command);
group.Controls.Add(new RibbonButton { Command = command });
}
}
你有沒有想過這個?我遇到了同樣的問題,無法通過代碼向現有組添加新項目。 – 2009-09-21 17:04:54