WPF Ribbon 4.0 - Size definition at control level

 ̄綄美尐妖づ 提交于 2019-12-10 23:39:01

问题


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!


回答1:


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>



回答2:


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.




回答3:


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




回答4:


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



来源:https://stackoverflow.com/questions/5161972/wpf-ribbon-4-0-size-definition-at-control-level

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!