Hi,
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">
<ribbon:Ribbon.Tabs>
<--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 --> />
</Ribbon.Tabs>
</Ribbon>
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"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:ef="clr-namespace:emmbeeFramework;assembly=emmbeeFramework.WPF"
xmlns:local="clr-namespace:FDB.Views"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ribbon="http://schemas.actiprosoftware.com/winfx/xaml/ribbon"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
mc:Ignorable="d">
<Grid>
<ribbon:Group Label="Group 1">
<!--First Button-->
<ribbon:Button x:Name="button1" Label="Button 1"
Command="{Binding CommandA}" <-- bind to CommandA in assembly CompanyViewModels -->
</ribbon:Button>
<!--Second Button-->
<ribbon:Button x:Name="button1" Label="Button 2"
Command="{Binding CommandB}" <-- bind to a CommandB in assembly CompanyViewModels -->
</ribbon:Button>
</ribbon:Group>
</Grid>
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
Get
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
Get
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
Michael