WPF Ribbon 4.0 - 控制级别的大小定义
我已经定义了类似的东西
<ribbon:RibbonGroup Header="Size at Control Level">
<ribbon:RibbonControlGroup>
<ribbon:RibbonButton SmallImageSource="Images\wizard-icon16.png" LargeImageSource="Images\wizard-icon32.png" Label="Button 1">
<ribbon:RibbonButton.ControlSizeDefinition>
<ribbon:RibbonControlSizeDefinition ImageSize="Large" IsLabelVisible="True"></ribbon:RibbonControlSizeDefinition>
</ribbon:RibbonButton.ControlSizeDefinition>
</ribbon:RibbonButton>
<ribbon:RibbonButton SmallImageSource="Images\wizard-icon16.png" LargeImageSource="Images\wizard-icon32.png" Label="Button 2">
<ribbon:RibbonButton.ControlSizeDefinition>
<ribbon:RibbonControlSizeDefinition ImageSize="Small" IsLabelVisible="True"></ribbon:RibbonControlSizeDefinition>
</ribbon:RibbonButton.ControlSizeDefinition>
</ribbon:RibbonButton>
<ribbon:RibbonButton SmallImageSource="Images\wizard-icon16.png" LargeImageSource="Images\wizard-icon32.png" Label="Button 3"></ribbon:RibbonButton>
<ribbon:RibbonButton SmallImageSource="Images\wizard-icon16.png" LargeImageSource="Images\wizard-icon32.png" Label="Button 4"></ribbon:RibbonButton>
</ribbon:RibbonControlGroup>
</ribbon:RibbonGroup>
但是所有按钮都很大。即使我为所有控件设置了 Small 的 ControlSizeDefinition 属性,它们仍然很大。我做错了什么?
谢谢!
I have defined something like this
<ribbon:RibbonGroup Header="Size at Control Level">
<ribbon:RibbonControlGroup>
<ribbon:RibbonButton SmallImageSource="Images\wizard-icon16.png" LargeImageSource="Images\wizard-icon32.png" Label="Button 1">
<ribbon:RibbonButton.ControlSizeDefinition>
<ribbon:RibbonControlSizeDefinition ImageSize="Large" IsLabelVisible="True"></ribbon:RibbonControlSizeDefinition>
</ribbon:RibbonButton.ControlSizeDefinition>
</ribbon:RibbonButton>
<ribbon:RibbonButton SmallImageSource="Images\wizard-icon16.png" LargeImageSource="Images\wizard-icon32.png" Label="Button 2">
<ribbon:RibbonButton.ControlSizeDefinition>
<ribbon:RibbonControlSizeDefinition ImageSize="Small" IsLabelVisible="True"></ribbon:RibbonControlSizeDefinition>
</ribbon:RibbonButton.ControlSizeDefinition>
</ribbon:RibbonButton>
<ribbon:RibbonButton SmallImageSource="Images\wizard-icon16.png" LargeImageSource="Images\wizard-icon32.png" Label="Button 3"></ribbon:RibbonButton>
<ribbon:RibbonButton SmallImageSource="Images\wizard-icon16.png" LargeImageSource="Images\wizard-icon32.png" Label="Button 4"></ribbon:RibbonButton>
</ribbon:RibbonControlGroup>
</ribbon:RibbonGroup>
But all the buttons are large. Even if I set a ControlSizeDefinition property with Small for all the controls, they still are large. What am I doing wrong?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
来自MSDN:功能区布局和调整大小(大约在页面的中间位置)小文字):
因此,如果多个 RibbonButton 位于公共
RibbonControlGroup
中(如您的示例所示),那么它们将始终共享相同的 RibbonControlSizeDefinition。在 WPF 功能区的当前状态下,您将无法指定不同的大小。您需要对它们进行不同的分组才能达到这样的效果。 (也许将它们放在边框内包裹的堆栈面板中......但我担心将非功能区控件放在功能区上有时会破坏功能区的良好内置功能)。我怀疑您真的不打算将所有四个按钮放在一个控制组中。
RibbonControlGroup
旨在“将非常密切相关的按钮粘合在一起”,因此一个按钮结束与下一个按钮开始之间的间距为 0。这对于不同尺寸的按钮效果不佳。我认为您可能只想将按钮直接放置在功能区组中,因为这实际上应该是告诉用户按钮以某种方式相关的容器。附加说明:您可以在 RibbonControlGroup 上指定一个尺寸定义,该定义将应用于其中的所有四个按钮,如下所示:
From MSDN: Ribbon Layout and Resizing (about halfway down the page in small text):
So if multiple RibbonButtons are in a common
RibbonControlGroup
(as your example shows) then they will always share the same RibbonControlSizeDefinition. In the current state of the WPF Ribbon, you will not be able to specify different sizes. You would need to group them differently to achieve such an effect. (maybe putting them in a stackpanel wrapped within a border... but I fear that putting non-ribbon controls onto the ribbon sometimes ruins the nice built in features of the ribbon).I suspect you really don't intend to put all four of your buttons within a single control group. A
RibbonControlGroup
is intended to 'glue very closely related buttons together' so there is 0 spacing between where one button ends and the next begins. This doesn't work well for buttons of different size. I think you may just want your buttons to be placed directly in the Ribbon Group, as that should really be the container that tells a user that the buttons are related somehow.An additional side note: You can specify a size definition on the RibbonControlGroup that will apply to all four of your buttons within it like so:
如果您设置了
SmallImageSource
并且未设置LargeImageSource
,则按钮应默认为小尺寸。If you set the
SmallImageSource
and don't set theLargeImageSource
, the button should default to the small size.你没有做错任何事。功能区工具栏会自动放大图像。如果空间不足,它将使用较小的图像来表示您指定为小的图像,并继续使用较大的图像来表示您指定为大的图像。但是,如果有空间显示大图像,它会尽可能地这样做。
当您填充功能区栏时,您应该会看到此行为。
You are not doing anything wrong. The ribbon toolbar is automatically scaling your images up. If it runs of space, it will use the smaller images for the ones you designate as small, and continue using the larger images for the ones you designate as large. But, if there's room to display large images, it will do that if it can.
You should see this behavior as you fill up your ribbon bar.
与 Scotts 的答案类似,但这样您就可以独立定义 RibbonButton 的大小,而不仅仅是组项目的大小。
https://stackoverflow.com/a/8601891/9758687
Similar to Scotts answer, but with this you could define the size of the RibbonButtons independently, not only the group items size.
https://stackoverflow.com/a/8601891/9758687