Put ItemsControl into RibbonTabItem

Nov 6, 2012 at 7:20 AM
Edited Nov 6, 2012 at 7:22 AM

Hi,

I'm wondering how can i do to put ItemsControl into RibbonTabItem

I try the following code but it doesn't work

 

<RibbonLibrary:RibbonGroupBox Header="Validation NT">
        <RibbonLibrary:Button Header="Afficher le workflow" Security:Access.SecurityFunction="Formula_Delete"  LargeIcon="Resources\Menu\Workflow.png" Size="Large" Command="{Binding DisplayWorkflowCommand}" />
    </RibbonLibrary:RibbonGroupBox>
    <ItemsControl ItemsSource="{Binding Groups}">
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <RibbonLibrary:RibbonGroupsContainer />
                <!-- <StackPanel Orientation="Horizontal" />-->
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <RibbonLibrary:RibbonGroupBox Header="{Binding Name}">
                    <RibbonLibrary:Button Header="{Binding Name}" LargeIcon="Resources\Validation\Agree.png" Size="Large" Command="{Binding AgreeCommand}" />
                    <RibbonLibrary:Button Header="{Binding Name}" LargeIcon="Resources\Validation\Disagree.png" Size="Large" Command="{Binding DesagreeCommand}" />
                </RibbonLibrary:RibbonGroupBox>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>

After changing RibbonTabItem.cs

 

/// <summary>
        /// get collection of ribbon groups
        /// </summary>
        public ObservableCollection<FrameworkElement> Groups
        {
            get
            {
                if (this.groups == null)
                {
                    this.groups = new ObservableCollection<FrameworkElement>();
                    this.groups.CollectionChanged += this.OnGroupsCollectionChanged;
                }
                return this.groups;
            }
        }

 

Thanks in advance

Developer
Nov 6, 2012 at 9:12 AM

This is not supported and i don't think it will ever be supported.

The approach i am using to control and fill the ribbon is by using a factory which gets fed by viewmodels and creates the appropiate controls (RibbonTabItem, RibbonGroupBox and everything else) in the ribbon.

If you try to continue implementing your approach, you will run into many problems (size reduction, scrolling, resizing, etc).

Nov 9, 2012 at 9:43 AM

Hi,

thanks for your answer. I finally use another solution to realise what I want. I use a messenger to send items, I want to add to the RibbonTabItem.

Developer
Nov 9, 2012 at 8:35 PM

Glad to hear that you found a solution.

Feb 21, 2013 at 5:31 PM
batzen wrote:
This is not supported and i don't think it will ever be supported. The approach i am using to control and fill the ribbon is by using a factory which gets fed by viewmodels and creates the appropiate controls (RibbonTabItem, RibbonGroupBox and everything else) in the ribbon. If you try to continue implementing your approach, you will run into many problems (size reduction, scrolling, resizing, etc).
Hello batzen,

I need the feature to fill the ribbon dynamicly via ViewModel. Can you please show a example how you implement it? Can I download anywhere a sampe-application for that procedures?

Thanks - it was very helpfull and save a lot of time for me if you can hel me
Developer
Feb 21, 2013 at 6:29 PM
Edited Feb 21, 2013 at 6:31 PM
I don't think that my employer will allow me to publish the code for the factory we are using.
But i will try to explain the basic concept:

On the ViewModel side we've got:
RibbonTabViewModel which has a list of
    RibbonGroupViewModel which has a list of
        ButtonCommandViewModel
        CheckBoxCommandViewModel
        ToggleButtonCommandViewModel
        continue this list for everything you need
Those all have properties like DisplayName, SmallImage, LargeImage etc..
In addition the RibbonTabViewModel has a Context property to realize contextual tabs.

The factory is kind of simple. It gets fed by an ObservableCollection of RibbonTabViewModels, listens to changes to that collection and creates the necessary RibbonTabs.
Then it listens to changes made to the ObservableCollection of RibbonGroupViewModels in each RibbonTabViewModel and creates the necessary RibbonGroups.
Then it listens to changes made to the ObservableCollection of CommandViewModels (the base class for all elements in a RibbonGroupViewModel) in each RibbonGroupViewModel and creates the necessary ribbon controls.

Of course there is more logic involved to handle things like context changes, building the applicationmenu/backstage etc. that's the reason why our "factory" class is called RibbonManager, as it handles all interaction with the Ribbon.

I hope this helps, at least, a bit. I'm afraid i'm not allowed to expose more of the inner workings of our RibbonManager. :-(