행이 편집 가능한 경우 "편집"하이퍼 링크를 표시해야하는 열 중 하나가있는 WPF DataGrid를 사용하고 있습니다. 이는 보조 모델에서 부울 플래그로 표시됩니다 행에. DataGridTemplateColumn을 사용하여이 작업을 수행 할 수있었습니다. 그러나 전체 행에 대한 추가 요구 사항은 행이 선택 될 때 하이라이트를 표시하지 않는 것입니다 (기본적으로 파란색 배경 임). 투명 배경으로 DataGridCell 스타일을 정의하여 다른 열에서이 작업을 수행 할 수있었습니다. DataGridCellStyle는 다음과 같이 정의된다WPF DataGrid의 DataGridTemplateColumn을 기반으로하는 열 스타일 지정
<DataGridTextColumn
Header="Id"
Binding="{Binding Path=Id}"
HeaderStyle="{StaticResource DataGridColumnHeaderStyle}"
CellStyle="{StaticResource 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>
감사 : 여기에 (행이 편집 가능한 경우 즉에 "편집"하이퍼 링크를 표시) 첫 번째 요구 사항을 만족하는 열의 내 구현입니다.
를 - 그것은 작동! Daniel 감사합니다. – Naresh