使用 WPF 功能区(适用于 .NET 4)和 RibbonControlSizeDefinition 对功能区项目大小进行项目级别控制 [英] Item level control over ribbon item sizes using WPF ribbon (for .NET 4) and RibbonControlSizeDefinition

查看:73
本文介绍了使用 WPF 功能区(适用于 .NET 4)和 RibbonControlSizeDefinition 对功能区项目大小进行项目级别控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据 MSDN 文档,一个功能区:RibbonControlSizeDefinition 可以用于通过设置 ControlSizeDefinition 属性来控制 WPF 功能区上项目的大小.有没有人成功使用过这个属性?我发现它完全被忽略了.我最初使用数据绑定设置它,但也尝试使用文件隐藏代码.

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.

这个问题类似,但它在 OP 使用 RibbonControlGroup 的评论之一中正确指出,因此看到了预期的行为.

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.

我在下面列出了我的 XAML 代码中不起作用的部分.

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>

推荐答案

经过一些实验,我有了一个解决方法.我尝试使用ribbon:RibbonGroup.GroupSizeDefinitions 属性使用组级大小而不是项目级大小.这如文档所示.此外,将其设置为空的 RibbonGroupSizeDefinition 足以使项目级属性工作.我上面的代码变成了:

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> 

这篇关于使用 WPF 功能区(适用于 .NET 4)和 RibbonControlSizeDefinition 对功能区项目大小进行项目级别控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆