Pergunta

I am trying to databind a ribbon control for dynamic menus.

<ribbon:Ribbon>
   <ribbon:RibbonTab Header="Reports"
        ItemsSource="{Binding ReportMenus}"
        ItemTemplate="{StaticResource RibbonGroupDataTemplate}">
    </ribbon:RibbonTab>
    <ribbon:RibbonTab Header="Test">
     <ribbon:RibbonGroup Header="TestGROUP"
      ItemsSource="{Binding ReportMenus}"
      ItemTemplate="{StaticResource RibbonButtonDataTemplate}">
     </ribbon:RibbonGroup>
    </ribbon:RibbonTab>
</ribbon:Ribbon>

The top ribbon tab is my 'real' ribbontab. The bottom started out as a manually built that I am verifying my theories with.

Here are the datatemplates I am trying to use:

<Style TargetType="{x:Type ribbon:RibbonButton}">
   <Setter Property="Label"
           Value="{Binding ReportDisplayName}" />
</Style>

<DataTemplate x:Key="RibbonButtonDataTemplate">
   <ribbon:RibbonButton />
</DataTemplate>

This is my first attempt at the Group DataTemplate:

<HierarchicalDataTemplate x:Key="RibbonGroupDataTemplate" DataType="{x:Type Ribbon:RibbonGroup}"
 ItemsSource="{Binding Converter={StaticResource DebugConverter}}"
 ItemTemplate="{StaticResource RibbonButtonDataTemplate}">
   <TextBlock Text="{Binding Path=ReportDisplayName}" />
</HierarchicalDataTemplate>

Then I was trying this one:

<DataTemplate x:Key="RibbonGroupDataTemplate">
  <ribbon:RibbonGroup ItemsSource="{Binding Converter={StaticResource DebugConverter}}"
          ItemTemplate="{StaticResource RibbonButtonDataTemplate}" />
</DataTemplate>

The problem is that I cant get the buttons to show up under the group. If I dont have a grouptemplate as in my second ribbontab, I can get it working. But if I try to do the group dynamically as well it fails to create the buttons. Also by doing the datatemplate with the ribbongroup inside of it, the headings get cutoff. I already read about that and that was the reason for trying to use the HierarchicalDatatemplate. The Regular Datatemplate does not allow for itemsource or itemtemplate.

So How do i get a dynamic RibbonGroup to show Dynamic RibbonButtons?


I have implemented some other changes now and its at least filling it in, however its not correct.

Right now it looks like this: alt text

I want it to look like this which is partially hardcoded. alt text

here is the xaml

<DataTemplate x:Key="RibbonButtonDataTemplate">
   <ribbon:RibbonButton />
</DataTemplate>

<HierarchicalDataTemplate x:Key="RibbonGroupDataTemplate"
                                  DataType="{x:Type ribbon:RibbonGroup}"
                                  ItemsSource="{Binding ReportsMenuCollection}"
                                  ItemTemplate="{StaticResource RibbonButtonDataTemplate}">
   <TextBlock Text="{Binding Path=ReportDisplayName}" />
</HierarchicalDataTemplate>

the only thing I have left to try is changing my RibbonButtonDataTemplate to a hierarchical datatemplate.

Foi útil?

Solução

You will need two Hierarchical data templates and two underlying binding entities one that represents a group and another that represents an item. The same concept would apply to a dynamic menu structure.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top