How to tie the team to RibbonGroup



  • There is a set of classes (unknown at the compilation stage) that provide a set of teams and a model of presentation that contains a collection of these classes. We need to show the team set. RibbonGroup On the tape.

    I can imagine that. I'm declaring my classrooms doing 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 presentation model, which contains the list of classes declared above:

    public MainVm
    {
    public ISomeClass[] SomeClasses { get; }

    public MainVm() 
    {
        SomeClasses = new[] { new ClassA(), new ClassB() };
    }
    

    }

    For the presentation of the auxiliary classes, I use the resource dictionaries:

    // представление 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>

    Part of the presentation 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 vocabulary of resources related to auxiliary class. I don't know how to put it in. RibbonGroup



  • You say you're tied to every class. ResourceDictionary♪ It's the idea to solve the problem.

    Put it in. ResourceDictionary as follows:

    // представление ClassA
    <ResourceDictionary ...>
        <DataTemplate DataType="{x:Type vm:ClassA}"> <!-- без ключа! -->
            <StackPanel Orientation="Horizontal">
                <RibbonButton Label="Command1" Command="{Binding Command1}" />
                <RibbonButton Label="Command2" Command="{Binding Command2}" />
            </StackPanel>
        </DataTemplate>
    </ResourceDictionary>
    

    Thus, ResourceDictionary View for this VM-class ClassA

    Now, this performance should be used in Ribbon. You have a few options for that. If for VM data, it's the only thing that needs to be done, all of it. ResourceDictionary Add it. MergedDictionary Total Application.Resources I'm sorry. If these VMs have another performance, gather everything. ResourceDictionary and add them to specific resources RibbonTabHuh.

    Next, your code should be just like this:

    <RibbonGroup Header="Main" ItemsSource="{Binding SomeClasses}"/>
    

    Your image will come from your classes. ResourceDictionary

    That's it.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2