An additional level of nesting appears when using the DataTemplate in the WPF ribbon application menu

I am using a WPF ribbon control provided by Microsoft.

The problem is that when I use the DataTemplate to populate the RibbonApplicationSplitMenuItem , I get an extra level of nesting, which I think should not be.

Here is the relevant WPF code:

 <Window.Resources> <DataTemplate DataType="{x:Type cfg:PluginInfoConfigurationElement}" x:Key="GotoPluginAppMenuItem"> <ribbon:RibbonApplicationMenuItem Header="{Binding Path=Key}" ImageSource="{Binding Path=Image}"/> </DataTemplate> </Window.Resources> <ribbon:RibbonApplicationMenu> <ribbon:RibbonApplicationSplitMenuItem x:Name="LoadPluginMenuItem" ItemsSource="{Binding Source={StaticResource NlpModel}, Path=AvailablePlugins}" Header="Plugins" ItemTemplate="{StaticResource GotoPluginAppMenuItem}"> </ribbon:RibbonApplicationSplitMenuItem> <ribbon:RibbonApplicationSplitMenuItem x:Name="LoadPluginMenuItem2" Header="Plugins"> <ribbon:RibbonApplicationMenuItem Header="FooPlugin" ImageSource="Images/icon-32.png"/> <ribbon:RibbonApplicationMenuItem Header="Invalid" ImageSource="Images/icon-32.png"/> </ribbon:RibbonApplicationSplitMenuItem> <!-- Other items to fill the menu --> </ribbon:RibbonApplicationMenu> 

And here is what I get:

with a DataTemplate With data template.

what I would like No template.

As you can see, when using the DataTemplate an additional level of nesting appears. How can I prevent this?

+4
source share
1 answer

Instead of setting an ItemTemplate you need to set an ItemContainerStyle , otherwise you end up with ribbon:RibbonApplicationMenuItem inside ribbon:RibbonApplicationMenuItem .

Jean Hominal: Here is the code that I used that achieved the desired result:

 <Style TargetType="{x:Type ribbon:RibbonApplicationMenuItem}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate> <ribbon:RibbonApplicationMenuItem Header="{Binding Path=Caption}" ImageSource="{Binding Path=Image}"/> </ControlTemplate> </Setter.Value> </Setter> </Style> 
+8
source

Source: https://habr.com/ru/post/1339791/


All Articles