2012-07-18 14 views
0

我正在爲我的色帶使用RibbonControlsLibrary(.Net 4.0)。我的實現是使用MVVM完全實現的。 現在我喜歡使用調整大小功能的好處。但我無法設置組框的縮減順序。這是因爲我必須按特殊順序定義組框的名稱。我無法設置組框的名稱,因爲我正在使用數據模板。 我試圖將功能區組框用戶控件的名稱綁定到datacontext上的一個屬性,但是我認爲這不起作用。在帶有MVVM的RibbonControlsLibrary中使用GroupSizeReductionOrder

那麼,我有沒有機會將功能區組框用戶控件名稱設置爲數據上下文的屬性?

+1

你能粘貼源代碼嗎? – kmatyaszek 2012-07-18 17:04:44

回答

0

設置RibbonGroups的名字

可能還有其他的解決方案,我的是實現一個Behavior,在OnAttached方法設置RibbonGroup的名字。

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,我認爲你必須要分配行爲添加到帶有樣式的RibbonGroup。 我一直在使用this solution成功。 如您所見,我的行爲代碼不提供所需的依賴項屬性,您必須添加它。

這裏是我的縮短絲帶的風格:

<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。

相關問題