在 WPF 功能区应用程序菜单中使用 DataTemplate 时会出现附加嵌套级别
我正在使用 Microsoft 提供的 WPF 功能区控件 。
问题在于,当我使用 DataTemplate 填充 RibbonApplicationSplitMenuItem 时,我得到了一个我认为不应该存在的额外嵌套级别。
这是相关的 WPF 代码:
<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>
这是我得到的:
正如您所看到的,使用 DataTemplate 时会出现额外的嵌套级别。我怎样才能防止这种情况发生?
I am using the WPF Ribbon control provided by Microsoft.
The problem consists in that, when I use a DataTemplate to fill a RibbonApplicationSplitMenuItem
, I get an additional nesting level that I believe should not be there.
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 Data Template.
Without the template.
As you can see, an additional nesting level appears when using a DataTemplate. How can I prevent that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要设置
ItemContainerStyle
而不是设置ItemTemplate
,否则您最终会在ribbon:RibbonApplicationMenuItem 内部得到一个
。ribbon:RibbonApplicationMenuItem
让·霍米纳尔:
这是我使用的代码,它达到了我想要的结果:
Instead of setting the
ItemTemplate
you need to setItemContainerStyle
otherwise you are ending up with aribbon:RibbonApplicationMenuItem
inside of theribbon:RibbonApplicationMenuItem
.Jean Hominal:
Here is the code that I have used, which achieved the result I wanted: