2016-05-25 79 views
1

我有一個GridControl,我使用一些單元格內的幾個按鈕進行單元編輯。如何在DevExpress GridControl中綁定實際的主題名稱CellTemplate

這與3個按鈕的樣品柱:

xmlns:dxet="http://schemas.devexpress.com/winfx/2008/xaml/editors/themekeys" 
xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid" 
xmlns:my="clr-namespace:MyProject.DevExpress.View" 


<dxg:GridColumn Width="Auto" 
       AllowEditing="False" 
       AutoFilterCondition="Default" 
       FieldName="Information" 
       Header="Info" 
       ShowInColumnChooser="False" 
       VisibleIndex="1"> 
       <dxg:GridColumn.CellTemplate> 
        <DataTemplate> 
         <dxe:ButtonEdit Name="PART_Editor" AllowDefaultButton="False"> 
          <dxe:ButtonEdit.Buttons>          
           <!-- Button Action 1 --> 
           <my:ButtonInfoCustom Tag="Info1"> 
            <my:ButtonInfoCustom.Template> 
             <DataTemplate> 
              <Button x:Name="PART_Item" 
                Height="Auto" 
                Content="{Binding DataContext.RowData.Row.InfoName}" 
                Style="{DynamicResource {dxet:ButtonsThemeKey ResourceKey=ButtonStyle, 
                            ThemeName=DeepBlue}}" 
                ToolTip="{Binding DataContext.RowData.Row.CustomTooltip}" /> 
             </DataTemplate> 
            </my:ButtonInfoCustom.Template> 
           </my:ButtonInfoCustom> 
           <!-- Button Action 2 --> 
           <my:ButtonInfoCustom Tag="Info2"> 
           ... 

問題是主題化

如果我設定的主題名稱明確,它的工作原理好嗎:

Style="{DynamicResource {dxet:ButtonsThemeKey ResourceKey=ButtonStyle, ThemeName=DeepBlue}}" 

如果我嘗試綁定:

Style="{DynamicResource {dxet:ButtonsThemeKey ResourceKey=ButtonStyle, ThemeName={Binding ThemeToUse}}}" 

我得到這個:

XamlParseException: 'Binding'不能在'ThemeName' 屬性中設置'ButtonsTh' emeKeyExtension」。 「綁定」只能在DependencyObject的DependencyProperty上設置爲 。

我該怎麼辦?

回答

0

那麼,你不應該把任何主題名稱放入你的XAML代碼。

相反,使用DevExpress內置控件,因爲它們考慮實際主題並相應地更改其外觀。

檢查這個例子(I完全除去Style標籤和替換ButtonSimpleButton):

<dxg:GridColumn Width="Auto" 
      AllowEditing="False" 
      AutoFilterCondition="Default" 
      FieldName="Information" 
      Header="Info" 
      ShowInColumnChooser="False" 
      VisibleIndex="1"> 
      <dxg:GridColumn.CellTemplate> 
       <DataTemplate> 
        <dxe:ButtonEdit Name="PART_Editor" AllowDefaultButton="False"> 
         <dxe:ButtonEdit.Buttons>          
          <!-- Button Action 1 --> 
          <my:ButtonInfoCustom Tag="Info1"> 
           <my:ButtonInfoCustom.Template> 
            <DataTemplate> 
             <dx:SimpleButton x:Name="PART_Item" 
               Height="Auto" 
               Content="{Binding DataContext.RowData.Row.InfoName}"                          ToolTip="{Binding DataContext.RowData.Row.CustomTooltip}" /> 
            </DataTemplate> 
           </my:ButtonInfoCustom.Template> 
          </my:ButtonInfoCustom> 
          <!-- Button Action 2 --> 
          <my:ButtonInfoCustom Tag="Info2"> 
    ... 
相關問題