
See this entry for the setup details to this question.
It's looking now that saying it worked was a bit premature. In the custom Ribbon class we use the following code to create a new Tab an add it to the Ribbon.Tabs collection:Where tabsSource is the new DP collection we added to the custom Ribbon class. We iterate through that to create Tabs from the VM's in that collection and then add those Tabs to the Ribbon.Tabs collection. Selector.IsSelected is bound to the VM's IsSelected property. The VM has been assigned to the DataContext of the Tab.
Then, at the click of a button in the app, we do the following to create a new Tab:Where miscTools is the VM that will back the Tab we are trying to create, and the custom Ribbon.TabsSource DP collection is bound to the Tools collection.
This creates a new Tab, but renders it as selected, along with whatever the last tab was that had been selected in the Ribbon. The content of the last selected Tab is still displayed on the Ribbon.
So the question is two-fold. First, why isn't the above working? And second, given that the above isn't working, is there a best-practice or workaround for creating a Tab at runtime and selecting it properly?
Thanks in advance.
It's looking now that saying it worked was a bit premature. In the custom Ribbon class we use the following code to create a new Tab an add it to the Ribbon.Tabs collection:
ribbonControl.Tabs.Clear();
foreach (var tools in tabsSource)
{
var tab = new Tab();
tab.DataContext = tools;
tab.Label = tools.Title;
var isSelectedBinding = new Binding
{
Mode = BindingMode.TwoWay,
Path = new PropertyPath("IsSelected"),
};
tab.SetBinding(Selector.IsSelectedProperty, isSelectedBinding);
ribbonControl.Tabs.Add(tab);
}
Then, at the click of a button in the app, we do the following to create a new Tab:
var miscTools = IoC.Get<MiscToolsViewModel>();
Tools.Add(miscTools);
miscTools.IsSelected = true;
This creates a new Tab, but renders it as selected, along with whatever the last tab was that had been selected in the Ribbon. The content of the last selected Tab is still displayed on the Ribbon.
So the question is two-fold. First, why isn't the above working? And second, given that the above isn't working, is there a best-practice or workaround for creating a Tab at runtime and selecting it properly?
Thanks in advance.