Using a usercontrol in a Ribbon

Ribbon for WPF Forum

Posted 8 years ago by Michael Bayer
Version: 16.1.0633


in my application I want a ribbon with a few ribbon tabs. One of these tabs should contain a usercontrol, which offers a group of ribbon buttons. This usercontrol is stored in another assembly than the ribbon. The viewmodel of the usercontrol is stored in a third assembly.

What I want to achieve is this:

the data of a company itself - like subsidiaries, contacts, employees, rate taxes, trade register excerpt and so on are needed in more than one application. So maybe we have a software to manage human resources (HR), another software for assetmanagement (AM) and a third software for anything else. All of these application need access to the company data.

Now the question is: in which of the three application should we offer the views to let the user manage the company data? If we implement it in the HR-software, an user who works only with the AM-Software cannot add his contacts.

The thought is: we implement the views in all of the three applications. For this purpose, we create a separate assembly (called "CompanyViews"), that just contains the views - and also the entire ribbon tab called "Company" in the form of usercontrols and the commands and events in a second assembly called "CompanyViewModels".

Then we reference CompanyViews and CompanyViewModels in all of our three main applications. Each ribbon of that main applications offers a tab "Company", which shows the usercontrol - the ribbon tab "Company"

This are my tentative steps:

Assembly1 (the main view). It contains the ribbon control with a few tabs. Tab 4 should display a user control.

<ribbon:Ribbon x:Name="ribbon" Grid.Row="0" DockPanel.Dock="Top">

	<--Tab 1-3 are inside MainView-->
          <ribbon:Tab Label="Tab 1"/>
          <ribbon:Tab Label="Tab 2"/>
	  <ribbon:Tab Label="Tab 3"/>

	  <-- Tab 4 is in a second assembly
	  <ribbon: <-- show ribbon tab "Company"-usercontrol here -->  />



 Assembly 2 (the usercontrol). I defined a grid with a ribbon group, that contains a few buttons. Every button should execute a command, which is stored in a separate viewmodel called CompanyViewModel (in fact, it looks horrible in the designer)

<UserControl x:Class="RibbonTabCompany"
        <ribbon:Group Label="Group 1">
            <!--First Button-->
            <ribbon:Button x:Name="button1" Label="Button 1"
                Command="{Binding CommandA}" <-- bind to CommandA in assembly CompanyViewModels -->

            <!--Second Button-->
            <ribbon:Button x:Name="button1" Label="Button 2"
                Command="{Binding CommandB}" <-- bind to a CommandB in assembly CompanyViewModels -->


Assembly 3 (the view model). This is a simple VB-class:


Imports System.Windows.Input
Imports ActiproSoftware.Windows

Public Class CompanyViewModel

    Private _commandACommand as Input.DelegateCommand(Of Object)
    Private _commandBCommand as Input.DelegateCommand(Of Object)
    Private _documentWindows As New DeferrableObservableCollection(Of DocumentViewModelBase)()

    'Constructor is injected from main application with an instance of
    'a DeferrableObservableCollection class, that represents the DocumentWindows of the main application.
    'This instance will be used for adding the documentwindows of the usercontrol to the collection with the AddDocumentWindow

    Public Sub New(documentWindows As DeferrableObservableCollection(Of DocumentViewModelBase))
        _documentWindows = documentWindows
    End Sub

    Public ReadOnly Property CommandACommand() As ICommand
            If _commandACommand Is Nothing Then
                _commandACommand = New Input.DelegateCommand(Of Object)(Sub(param) Me.commandADocument(True))
            End If
            Return _commandACommand
        End Get
    End Property

    Public Sub CommandA()
        'Do anything
    End Sub

    Public ReadOnly Property CommandBCommand() As ICommand
            If _commandBCommand Is Nothing Then
                _commandBCommand = New Input.DelegateCommand(Of Object)(Sub(param) Me.commandBDocument(True))
            End If
            Return _commandBCommand
        End Get
    End Property

    Public Sub CommandB()
        'Do anything
    End Sub

End Class


As you can imagine, this doesn't work. I've already created an application, that has a ribbon control, whose buttons binds to a separate ViewModels-assembly. But how can I achieve my aim and implement a ribbon tab as usercontrol?

Many thanks for reading and your support


Comments (2)

Answer - Posted 8 years ago by Actipro Software Support - Cleveland, OH, USA

Hi Michael,

While you can't interject controls like UserControls and Grid in between a ribbon:Tab and its ribbon:Groups, you can do what we did in our sample project under /ProductSamples/RibbonSamples/Common/WordHomeTab.xaml where that root class is a ribbon:Tab itself.  And in effect you end up using it like a UserControl.

Actipro Software Support

Posted 8 years ago by Michael Bayer

This is exact what I want.

Thank you very much.

The latest build of this product (v24.1.2) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.