Tab.IsSelected confusion

Ribbon for WPF Forum

Posted 8 years ago by Scott Huiskens
Version: 11.1.0541
Avatar
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:
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);
}
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:

var miscTools = IoC.Get<MiscToolsViewModel>();
Tools.Add(miscTools);
miscTools.IsSelected = true;
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.

Comments (1)

Posted 8 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Scott,

For questions like this that require some sort of repro, please always email us a new simple sample project that shows the issue. That way we can debug it and answer your questions. Make sure your ZIP doesn't include any .exe files and rename the .zip file extension so it doesn't get spam blocked.

Setting the ribbon.SelectedTab to the appropriate tab should always work ok as a workaround.


Actipro Software Support

The latest build of this product (v2019.1 build 0681) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.