在运行时构建 wpf Ribbon
我正在尝试对动态菜单的功能区控件进行数据绑定。
<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>
顶部的功能区选项卡是我的“真正的”功能区选项卡。底部最初是手动构建的,我正在用它验证我的理论。
以下是我尝试使用的数据模板:
<Style TargetType="{x:Type ribbon:RibbonButton}">
<Setter Property="Label"
Value="{Binding ReportDisplayName}" />
</Style>
<DataTemplate x:Key="RibbonButtonDataTemplate">
<ribbon:RibbonButton />
</DataTemplate>
这是我第一次尝试组数据模板:
<HierarchicalDataTemplate x:Key="RibbonGroupDataTemplate" DataType="{x:Type Ribbon:RibbonGroup}"
ItemsSource="{Binding Converter={StaticResource DebugConverter}}"
ItemTemplate="{StaticResource RibbonButtonDataTemplate}">
<TextBlock Text="{Binding Path=ReportDisplayName}" />
</HierarchicalDataTemplate>
然后我尝试这个:
<DataTemplate x:Key="RibbonGroupDataTemplate">
<ribbon:RibbonGroup ItemsSource="{Binding Converter={StaticResource DebugConverter}}"
ItemTemplate="{StaticResource RibbonButtonDataTemplate}" />
</DataTemplate>
问题是我无法让按钮显示在组下。如果我没有第二个功能区选项卡中的组模板,我可以让它工作。 但是,如果我尝试动态地进行分组,则无法创建按钮。此外,通过使用其中的功能区组执行数据模板,标题也会被截断。我已经读过相关内容,这就是尝试使用 HierarchicalDatatemplate 的原因。常规数据模板不允许使用 itemsource 或 itemtemplate。
那么如何获得动态 RibbonGroup 来显示动态 RibbonButtons?
我现在已经实施了一些其他更改,并且至少填充了它,但它不正确。
现在看起来像这样:
我希望它看起来像这样,部分是硬编码的。
这是 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>
我唯一要做的就是将 RibbonButtonDataTemplate 更改为分层数据模板。
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:
I want it to look like this which is partially hardcoded.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您将需要两个分层数据模板和两个底层绑定实体,一个表示组,另一个表示项目。相同的概念也适用于动态菜单结构。
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.