Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Item level control over ribbon item sizes using WPF ribbon (for .NET 4) and RibbonControlSizeDefinition

Tags:

wpf

ribbon

According to the MSDN documentation, a ribbon:RibbonControlSizeDefinition can be used to control the size of an item on a WPF ribbon by setting the ControlSizeDefinition property. Has anyone had any success using this property? I find that it is completely ignored. I initially set it using data binding, but have also tried using the code behind file.

This question is similar, but it is correctly noted in one of the comments that the OP had used a RibbonControlGroup, and therefore was seeing the expected behaviour.

I understand that it's usually best to allow the ribbon to do it's own thing regarding sizing. Sadly that's not an option for this project.

I've listed the part of my XAML code that doesn't work below.

    <ribbon:RibbonTab Header="MyTab">
        <ribbon:RibbonGroup Header="MyGroup">
            <ribbon:RibbonButton Label="My big button" Name="BigButton"
                                 LargeImageSource="Images\Ribbon\assignments_duties_a2k_32.png"
                                 SmallImageSource="Images\Ribbon\assignments_duties_a2k_16.png">
                <ribbon:RibbonButton.ControlSizeDefinition>
                    <ribbon:RibbonControlSizeDefinition ImageSize="Large" IsLabelVisible="True" />
                </ribbon:RibbonButton.ControlSizeDefinition>
            </ribbon:RibbonButton>
            <ribbon:RibbonButton Label="My little button" Name="SmallButton"
                                 LargeImageSource="Images\Ribbon\assignments_duties_a2k_32.png"
                                 SmallImageSource="Images\Ribbon\assignments_duties_a2k_16.png">
                <ribbon:RibbonButton.ControlSizeDefinition>
                    <ribbon:RibbonControlSizeDefinition ImageSize="Small" IsLabelVisible="True" />
                </ribbon:RibbonButton.ControlSizeDefinition>
            </ribbon:RibbonButton>
        </ribbon:RibbonGroup>
    </ribbon:RibbonTab>
like image 818
Olly Avatar asked Dec 21 '11 21:12

Olly


1 Answers

After some experimentation, I have a workaround. I tried using group-level sizing instead of item-level sizing, using the ribbon:RibbonGroup.GroupSizeDefinitions property. This works as documented. Additionally, setting this to an empty RibbonGroupSizeDefinition is enough to make the item-level properties work. My code from above becomes:

<ribbon:RibbonTab Header="MyTab">
     <ribbon:RibbonGroup Header="MyGroup">

            <ribbon:RibbonGroup.GroupSizeDefinitions>
                <ribbon:RibbonGroupSizeDefinition>
                </ribbon:RibbonGroupSizeDefinition>
            </ribbon:RibbonGroup.GroupSizeDefinitions>

         <ribbon:RibbonButton Label="My big button" Name="BigButton"                                  LargeImageSource="Images\Ribbon\assignments_duties_a2k_32.png"                                  SmallImageSource="Images\Ribbon\assignments_duties_a2k_16.png">
                <ribbon:RibbonButton.ControlSizeDefinition>
                    <ribbon:RibbonControlSizeDefinition ImageSize="Large" IsLabelVisible="True" />
                </ribbon:RibbonButton.ControlSizeDefinition>
         </ribbon:RibbonButton>
         <ribbon:RibbonButton Label="My little button" Name="SmallButton"                                  LargeImageSource="Images\Ribbon\assignments_duties_a2k_32.png"                                  SmallImageSource="Images\Ribbon\assignments_duties_a2k_16.png">
                <ribbon:RibbonButton.ControlSizeDefinition>
                    <ribbon:RibbonControlSizeDefinition ImageSize="Small" IsLabelVisible="True" />
                </ribbon:RibbonButton.ControlSizeDefinition>
         </ribbon:RibbonButton>
     </ribbon:RibbonGroup>
 </ribbon:RibbonTab> 
like image 78
Olly Avatar answered Nov 10 '22 23:11

Olly