功能区应用菜单辅助窗格大小
如何更改 WPF 功能区应用程序菜单中 AuxilaryPane 的大小?我已将最近的文件列表添加到该区域,但它被截断了。理想情况下,我希望辅助窗格像 Word/Excel 一样填满屏幕。
我的代码:
<r:Ribbon.ApplicationMenu>
<r:RibbonApplicationMenu>
<r:RibbonApplicationMenu.AuxiliaryPaneContent>
<StackPanel>
<TextBlock Text="Recent Files" />
<Separator />
<ItemsControl ItemsSource="{Binding RecentFiles}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<r:RibbonApplicationMenuItem Header="{Binding ShortPath}"
Command="{Binding DataContext.OpenRecentFileCommand, RelativeSource={RelativeSource AncestorType=ItemsControl}}"
CommandParameter="{Binding LongPath}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</r:RibbonApplicationMenu.AuxiliaryPaneContent>
</r:RibbonApplicationMenu>
</r:Ribbon.ApplicationMenu>
How do I change the size of the AuxilaryPane in the WPF Ribbon ApplicationMenu? I have added a recent file list to that area but it is getting truncated. Ideally I'd like the auxilary pane to fill the screen like it does for Word/Excel.
My code:
<r:Ribbon.ApplicationMenu>
<r:RibbonApplicationMenu>
<r:RibbonApplicationMenu.AuxiliaryPaneContent>
<StackPanel>
<TextBlock Text="Recent Files" />
<Separator />
<ItemsControl ItemsSource="{Binding RecentFiles}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<r:RibbonApplicationMenuItem Header="{Binding ShortPath}"
Command="{Binding DataContext.OpenRecentFileCommand, RelativeSource={RelativeSource AncestorType=ItemsControl}}"
CommandParameter="{Binding LongPath}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</r:RibbonApplicationMenu.AuxiliaryPaneContent>
</r:RibbonApplicationMenu>
</r:Ribbon.ApplicationMenu>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
如果您正在寻找一种非常快速的解决方案来增加高度,您可以简单地添加一些无用的 RibbonApplicationMenuItems 来填充框(并且不必修改 MS 源代码)。
If you are looking for a very quick fix to increase the height, you can simply add some useless RibbonApplicationMenuItems to pad out the box (and not have to modify MS source code).
我已经找到了同样问题的解决方案。
没有直接属性可以修改它。
创建此类属性的示例可以在以下位置找到:
msdn
这是主要解决方案:
更改Ribbon库的源代码。 MS 提供了 Ribbon 库的源代码:http://www.microsoft.com/downloads/en/details.aspx?FamilyID=2bfc3187-74aa-4154-a670-76ef8bc2a0b4
下载源代码并打开,在MicrosoftRibbonForWPFSourceAndSamples\RibbonControlsLibrary\Microsoft\Windows\Controls\Ribbon\RibbonApplicationMenu.cs,添加一个依赖属性:
在 MicrosoftRibbonForWPFSourceAndSamples\RibbonControlsLibrary\Themes\Generic.xaml 的第 7519 行中,添加 XAML 代码:
仅添加给定的前两行数据文件
I've searched a solution for the same problem.
There is no direct property to modify this.
An Example of creating such property can be found at
msdn
here's the main solution:
Change the source code of the Ribbon Library. MS has provided the source code of the Ribbon Library: http://www.microsoft.com/downloads/en/details.aspx?FamilyID=2bfc3187-74aa-4154-a670-76ef8bc2a0b4
Download the source code and open it, in the MicrosoftRibbonForWPFSourceAndSamples\RibbonControlsLibrary\Microsoft\Windows\Controls\Ribbon\RibbonApplicationMenu.cs, add one Dependency Property:
In the MicrosoftRibbonForWPFSourceAndSamples\RibbonControlsLibrary\Themes\Generic.xaml, line 7519, add the XAML code:
Only add the first two rows of the given xaml
是的,这是一个旧线程,它有一些好主意,但我不满意。
我的问题略有不同,因为我需要 ApplicationMenu 扩展至足以容纳放置在辅助窗格中的任何控件。
最终我深入挖掘并找到了一个令我满意的解决方案。它不能解决“填满屏幕”的问题,但我希望这能帮助那些登陆这里、寻找与我类似的问题的解决方案的人。抱歉,如果看起来我想劫持该线程。我无意。
本质上,我通过更改功能区样式解决了固定宽度和高度问题:
此时您可能会问,“为什么不直接使用 VS 或 Blend 或 ShowMeTheTemplate 而不是 DotPeek?”所有这些工具在色带组件上都惨遭失败。不知道为什么。他们没有说。使用DotPeek的问题之一是一些命名空间引用需要调整,但这并不是太困难,所以这里不再赘述。
因此,现在您已经拥有了所有样式和模板,接下来就可以查找有问题的标记了。
首先,固定宽度:
。只有一个。“300”
更改为“自动”
。然后修复高度:
PART_SubmenuPlaceholder
边框的定义。您可以搜索x:Name="PART_SubmenuPlaceholder"
。它比您对宽度所做的更改低大约 50 行。Height="{Binding ElementName=MainPaneBorder, Path=ActualHeight}"
。现在您已经修改了样式,只需将此资源字典添加到您的 xaml 中,它就会应用到功能区。
This is an old thread, yes, and it has some good ideas, but I wasn't satisfied.
My problem was slightly different in that I needed the ApplicationMenu to expand only enough to fit any control that was placed in the auxiliary pane.
Eventually I dug deep and found a solution I was happy with. It doesn't solve the "fill the screen" problem, but I'm hoping this will help others who land here, looking for a solution to a problem similar to mine. Sorry if it looks like I'm trying to hijack the thread. I don't intend to.
Essentially I solved the fixed width and height problem by changing the ribbon style:
At this point you may be asking, "Why not just use VS or Blend or ShowMeTheTemplate instead of DotPeek?" All of these tools failed miserably on the ribbon assembly. Don't know why. They didn't say. One of the problems with using DotPeek is that some of the namespace references will need adjusting, but it's not too difficult, so I won't go into details here.
So, now that you have all the styles and templates, go look for the offending markup.
First, fix the width:
<ColumnDefinition Width="300"/>
. There is only one."300"
to"Auto"
.Then fix the height:
PART_SubmenuPlaceholder
Border. You can search forx:Name="PART_SubmenuPlaceholder"
. It is about 50 lines below the change you did for the width.Height="{Binding ElementName=MainPaneBorder, Path=ActualHeight}"
.Now that you've modified the style, just add this resource dictionary to your xaml and it should apply itself to the ribbon.
当我遇到这个答案时(在寻找我自己的略有不同问题的答案时),我对实际修改 Microsoft 代码并不太感兴趣。
因此,我宁愿对其进行子类化,并在相关的“PART_...”上使用
base.GetTemplateChild
获取必要的 UI 元素。我想您可以遵循类似的方法来实现您所需要的。
我的示例位于此处。
希望这有帮助。
PS 如果您碰巧找到一种方法来确定 AuxiliaryPanel 的必要宽度,请告诉我 - 我想看看这是否也适用于菜单的宽度。
When I came across this answer (while searching for an answer to my own, slightly different question), I wasn't too excited about actually modifying Microsoft code.
As a result, I rather preferred to subclass it, and get the hold of the necessary UI element using
base.GetTemplateChild
on the relevant "PART_...".I suppose you can follow a similar approach to achieve what you need.
My example is here.
Hope this helps.
P.S. If you happen to find a way to determine the necessary width of the AuxiliaryPanel, please let me know - I would like to see if that's applicable to the menu's width as well.
您可以下载 Microsoft Ribbon for WPF 源代码 (http:// www.microsoft.com/en-us/download/details.aspx?id=11877)并将 DependencyProperty 宽度/高度添加到 ApplicationMenu 或只是“快速而肮脏”地进行在我的示例中:
MainWindow.xaml
MainWindow.xaml.cs
度过了愉快的一天
You can download the Microsoft Ribbon for WPF Source Code (http://www.microsoft.com/en-us/download/details.aspx?id=11877) and add a DependencyProperty Width/Height to ApplicationMenu or just do it 'quick and dirty' like in my example:
MainWindow.xaml
MainWindow.xaml.cs
have a nice day
根据此线程中的答案,我发现最简单的方法是子类化 RibbonApplicationMenu 并将第三列的宽度设置为自动。
现在您只需将 Ribbon xaml 从 更改
为
Based on the answers in this thread I found it easiest to subclass RibbonApplicationMenu and set Width of the third column to Auto.
Now you just need to change your Ribbon xaml from
to