2010-04-25 59 views
2

我正在使用WPF DataGrid,其中一列需要顯示「編輯」超鏈接(如果該行可編輯) - 這由支持模型中的布爾標誌指示爲行。我能夠使用DataGridTemplateColumn實現這一點 - 沒有問題。然而,對於整行的額外要求是在選擇行時(默認情況下是藍色背景)不顯示任何高亮。通過用透明背景定義DataGridCell樣式,我已經能夠在其他列上實現這一點,例如基於WPF數據網格中的DataGridTemplateColumn的樣式列

<DataGridTextColumn 
    Header="Id" 
    Binding="{Binding Path=Id}" 
    HeaderStyle="{StaticResource DataGridColumnHeaderStyle}" 
    CellStyle="{StaticResource DataGridCellStyle}" /> 

其中DataGridCellStyle定義如下:

<Style x:Key="DataGridCellStyle" TargetType="{x:Type DataGridCell}"> 
    <Setter Property="Background" Value="Transparent" /> 
    ... 
</Style> 

但是所討論的柱,DataGridTemplateColumn,不提供「CellStyle」屬性,我可以使用用於截止選擇亮點。所以我的問題是如何在使用DataGridTemplateColumn時設置單元格樣式?這是我滿足第一個要求的列的實現(即如果該行可編輯,則顯示「編輯」超鏈接):

<DataGridTemplateColumn 
    Header="Actions" 
    HeaderStyle="{StaticResource CenterAlignedColumnHeaderStyle}"> 
    <DataGridTemplateColumn.CellTemplate> 
     <DataTemplate> 
      <TextBlock 
       Visibility="{Binding Path=Editable, Converter={StaticResource convVisibility}}" 
       Style="{StaticResource CenterAlignedElementStyle}"> 
        <Hyperlink 
         Command="..." 
         CommandParameter="{Binding}"> 
         <TextBlock Text="Edit" /> 
        </Hyperlink> 
      </TextBlock> 
     </DataTemplate> 
    </DataGridTemplateColumn.CellTemplate> 
</DataGridTemplateColumn> 

謝謝。

回答