WPF Ribbon 4.0 - 控制级别的大小定义

发布于 2024-10-19 14:11:57 字数 1765 浏览 3 评论 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

救星 2024-10-26 14:11:57

来自MSDN:功能区布局和调整大小(大约在页面的中间位置)小文字):

对照组

相关的功能区控件可以组合在一起
RibbonControlGroup。当调整控制组大小时,一个
RibbonControlSizeDefinition 应用于所有控件
RibbonControlGroup
。 RibbonControlGroup 位于
RibbonGroup 就好像它是一个控件。

因此,如果多个 RibbonButton 位于公共 RibbonControlGroup 中(如您的示例所示),那么它们将始终共享相同的 RibbonControlSizeDefinition。在 WPF 功能区的当前状态下,您将无法指定不同的大小。您需要对它们进行不同的分组才能达到这样的效果。 (也许将它们放在边框内包裹的堆栈面板中......但我担心将非功能区控件放在功能区上有时会破坏功能区的良好内置功能)。

我怀疑您真的不打算将所有四个按钮放在一个控制组中。 RibbonControlGroup 旨在“将非常密切相关的按钮粘合在一起”,因此一个按钮结束与下一个按钮开始之间的间距为 0。这对于不同尺寸的按钮效果不佳。我认为您可能只想将按钮直接放置在功能区组中,因为这实际上应该是告诉用户按钮以某种方式相关的容器。

附加说明:您可以在 RibbonControlGroup 上指定一个尺寸定义,该定义将应用于其中的所有四个按钮,如下所示:

<ribbon:RibbonGroup Header="Size at Control Level">
    <ribbon:RibbonControlGroup>
        <ribbon:RibbonControlGroup.ControlSizeDefinition>
            <r:RibbonControlSizeDefinition ImageSize="Small" IsLabelVisible="False" />
        </ribbon:RibbonControlGroup.ControlSizeDefinition>
        <ribbon:RibbonButton SmallImageSource="Images\wizard-icon16.png" LargeImageSource="Images\wizard-icon32.png" Label="Button 1" />
        <ribbon:RibbonButton SmallImageSource="Images\wizard-icon16.png" LargeImageSource="Images\wizard-icon32.png" Label="Button 2" />
        <ribbon:RibbonButton SmallImageSource="Images\wizard-icon16.png" LargeImageSource="Images\wizard-icon32.png" Label="Button 3" />
        <ribbon:RibbonButton SmallImageSource="Images\wizard-icon16.png" LargeImageSource="Images\wizard-icon32.png" Label="Button 4" />
    </ribbon:RibbonControlGroup>
</ribbon:RibbonGroup>

From MSDN: Ribbon Layout and Resizing (about halfway down the page in small text):

Control Groups

Related ribbon controls can be grouped together in a
RibbonControlGroup. When a control group is resized, one
RibbonControlSizeDefinition is applied to all of the controls in the
RibbonControlGroup
. The RibbonControlGroup is positioned in the
RibbonGroup as if it were one control.

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:

<ribbon:RibbonGroup Header="Size at Control Level">
    <ribbon:RibbonControlGroup>
        <ribbon:RibbonControlGroup.ControlSizeDefinition>
            <r:RibbonControlSizeDefinition ImageSize="Small" IsLabelVisible="False" />
        </ribbon:RibbonControlGroup.ControlSizeDefinition>
        <ribbon:RibbonButton SmallImageSource="Images\wizard-icon16.png" LargeImageSource="Images\wizard-icon32.png" Label="Button 1" />
        <ribbon:RibbonButton SmallImageSource="Images\wizard-icon16.png" LargeImageSource="Images\wizard-icon32.png" Label="Button 2" />
        <ribbon:RibbonButton SmallImageSource="Images\wizard-icon16.png" LargeImageSource="Images\wizard-icon32.png" Label="Button 3" />
        <ribbon:RibbonButton SmallImageSource="Images\wizard-icon16.png" LargeImageSource="Images\wizard-icon32.png" Label="Button 4" />
    </ribbon:RibbonControlGroup>
</ribbon:RibbonGroup>
岛徒 2024-10-26 14:11:57

如果您设置了 SmallImageSource 并且未设置 LargeImageSource,则按钮应默认为小尺寸。

If you set the SmallImageSource and don't set the LargeImageSource, the button should default to the small size.

一直在等你来 2024-10-26 14:11:57

你没有做错任何事。功能区工具栏会自动放大图像。如果空间不足,它将使用较小的图像来表示您指定为小的图像,并继续使用较大的图像来表示您指定为大的图像。但是,如果有空间显示大图像,它会尽可能地这样做。

当您填充功能区栏时,您应该会看到此行为。

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.

不必你懂 2024-10-26 14:11:57

与 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文