0

我正在为我的功能区使用 RibbonControlsLibrary (.Net 4.0)。我的实现完全是使用 MVVM 实现的。现在我喜欢使用调整大小功能的好处。但我无法设置组框的减少顺序。这是因为我必须以特殊顺序定义组框的名称。我无法设置分组框的名称,因为我使用的是数据模板。我试图将功能区组框用户控件的名称绑定到 datacontext 上的属性,但我认为这不起作用。

那么,我是否有机会将功能区组框用户控件名称设置为数据上下文的属性?

4

1 回答 1

0

设置功能区组的名称

可能还有其他解决方案,我的是实现一个在 OnAttached 方法中设置 RibbonGroup 名称的 Behavior

public class RibbonGroupNameBehavior : Behavior<RibbonGroup>
{
    protected override void OnAttached()
    {
        base.OnAttached();

        GroupeCommandesViewModel groupeCommandesViewModel = this.AssociatedObject.DataContext as GroupeCommandesViewModel;
        if (groupeCommandesViewModel != null)
        {
            this.AssociatedObject.Name = groupeCommandesViewModel.Nom;
        }
    }
}

您可能想在分配周围添加一个 try-catch 块...

使用行为

当您使用 DataTemplates 时,我认为您必须将行为分配给带有样式的 RibbonGroups。我一直在成功使用这个解决方案。如您所见,我的行为代码没有提供所需的依赖属性,您必须添加它。

这是我缩短的 Ribbon 的样式:

<r:Ribbon.Style>
    <Style TargetType="{x:Type r:Ribbon}">
        <Setter Property="ItemContainerStyle">
            <Setter.Value>
                <Style TargetType="{x:Type r:RibbonTab}">
                    <Setter Property="ItemsSource" Value="{Binding ListeCommandes, Converter={StaticResource CommandesToGroupesConverter}}" />
                    <Setter Property="GroupSizeReductionOrder" Value="{Binding ListeCommandesOrdreRedimensionnement}" />
                    <Setter Property="ItemContainerStyleSelector">
                        <Setter.Value>
                            <ribbonVM:RibbonGroupStyleSelector>
                                <ribbonVM:RibbonGroupStyleSelector.GenericStyle>
                                    <Style TargetType="{x:Type r:RibbonGroup}" BasedOn="{StaticResource RibbonGroupStyle}" />
                                </ribbonVM:RibbonGroupStyleSelector.GenericStyle>
                            </ribbonVM:RibbonGroupStyleSelector>
                        </Setter.Value>
                    </Setter>
                </Style>
            </Setter.Value>
        </Setter>
    </Style>
</r:Ribbon.Style>

还有我的 RibbonGroup 的风格:

<Style x:Key="RibbonGroupStyle"  TargetType="{x:Type r:RibbonGroup}" BasedOn="{StaticResource RibbonControlStyle}">
    <Setter Property="Header"       Value="{Binding Libellé}" />
    <Setter Property="ItemsSource"  Value="{Binding Commandes}" />

    <Setter Property="CanAddToQuickAccessToolBarDirectly" Value="False" />

    <Setter Property="ihm_behaviors:RibbonGroupNameBehavior.IsEnabled" Value="True" />
</Style>

数据绑定 GroupSizeReductionOrder 属性

如果您查看 GroupSizeReductionOrder 属性的定义,您会看到它是一个带有 TypeConverter StringCollectionConverter 的 StringCollection。据我所见,此转换器仅从字符串转换为 StringCollection。因此,您的属性应该是字符串或 StringCollection。

于 2013-02-26T18:07:30.273 回答