我用RibbonControlsLibrary (.Net 4.0)来装饰我的丝带。我的实现完全是使用MVVM实现的。现在,我喜欢使用调整大小功能的好处。但我不能设置分组框的缩减顺序。这是因为我必须以特殊的顺序定义组框的名称。我不能设置组框的名称,因为我正在使用数据模板。我试图将功能区分组框用户控件的名称绑定到datacontext上的一个属性,但正如我所想的那样,这不起作用。
那么,我是否有机会将功能区组框用户控件名称设置为数据上下文的属性?
发布于 2013-02-27 02:07:30
设置RibbonGroups的名称
可能还有其他解决方案,我的解决方案是实现一个在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。我已经成功地使用了this solution。正如您将看到的,我的行为代码没有提供所需的依赖属性,您必须添加它。
以下是我缩短的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。
https://stackoverflow.com/questions/11539822
复制相似问题