Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

How to dynamically add tab to ribbon using code

$
0
0

I am working on a project which need load the Ribbon tab dynamically based on the configuration when the program starts up. I can only found a way to add the tab to the Ribbon as 

Ribbon.Items.Add(tab)

But an exception throw out:

Items collection must be empty before using ItemsSource.

Here is the code in xaml:

    <Grid Name="RootGrid">
        <Grid.RowDefinitions>
            <RowDefinition Height="140"></RowDefinition>
            <RowDefinition></RowDefinition>
        </Grid.RowDefinitions>

<ribbon:Ribbon Name="m_RibbonRoot"/>

        <Grid Name="m_WindowContent" Grid.Row="1">
            <!-- Here is the content of the window-->
        </Grid>
    </Grid>

Here is the code behind:

        private void InitializeRibbonUI()
        {
            var tabs = RibbonUIManager.Instance.GetTabList();     //Get the list of the tabs from the configuration
            foreach (var tab in tabs)
            {
                m_RibbonRoot.Items.Add(tab);                               //Exception thrown: Items collection must be empty before using ItemsSource.
            }
         }

I am using Ribbon for WPF (System.Windows.Controls.Ribbon) in .net 4.5.1

Thank you very much

Best regards,

Xin 



Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>