There is a set of classes (unknown at compile time) that provide a set of commands, and a view model that contains a collection of these classes. Need to show a set of commands in the RibbonGroup on the tape.
I imagine it like this. I declare my classes that implement some empty interface:
public ClassA : ISomeClass { public ICommand Command1 { get; } public ICommand Command2 { get; } } public ClassB : ISomeClass { public ICommand Command3 { get; } } We declare the main window view model, which contains a list of the classes declared above:
public MainVm { public ISomeClass[] SomeClasses { get; } public MainVm() { SomeClasses = new[] { new ClassA(), new ClassB() }; } } I use resource dictionaries to represent helper classes:
// представление ClassA <ResourceDictionary ...> <RibbonButton x:Key="Command1_ItemKey" Label="Command1" Command="{Binding Command1}" /> <RibbonButton x:Key="Command2_ItemKey" Label="Command2" Command="{Binding Command2}" /> </ResourceDictionary> // представление ClassB <ResourceDictionary ...> <RibbonButton x:Key="Command3_ItemKey" Label="Command3" Command="{Binding Command3}" /> </ResourceDictionary> The presentation part for the main presentation model:
<RibbonTab Header="Home"> <RibbonGroup Header="Main" ItemsSource="{Binding SomeClasses}"> // вот здесь непонятно, что делать. Нужно каким-то образом связать каждый конкретный элемент со списком кнопок в представлении </RibbonGroup> </RibbonTab> I can get a collection of buttons from a resource dictionary associated with a specific auxiliary class. I do not understand how it can be inserted into the RibbonGroup .