I'm using the WPF Office Ribbon, and I have a content view that I would like to have add new items to the ribbon when that view becomes active. I have code that adds a new RibbonCommand as well as a new RibbonButton to the group I want, but nothing happens when I add it. However, if I add a new group with the button, it comes up fine and is bound correctly. Is there some method to get it to update that I'm missing? I've tried UpdateLayout() and it does not work either. I'd really like to try and avoid rebuilding all the groups everytime the view changes.
Works:
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);
}
Doesn't Work:
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 });
}
}